Skip to content

Commit

Permalink
apply cs fixer automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickjahns committed May 16, 2018
1 parent 92fcdd5 commit 5f0af49
Show file tree
Hide file tree
Showing 1,406 changed files with 7,385 additions and 8,645 deletions.
10 changes: 5 additions & 5 deletions apps/comments/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
$eventDispatcher = \OC::$server->getEventDispatcher();
$eventDispatcher->addListener(
'OCA\Files::loadAdditionalScripts',
function() {
function () {
\OCP\Util::addScript('oc-backbone-webdav');
\OCP\Util::addScript('comments', 'app');
\OCP\Util::addScript('comments', 'commentmodel');
Expand All @@ -37,14 +37,14 @@ function() {
);

$activityManager = \OC::$server->getActivityManager();
$activityManager->registerExtension(function() {
$activityManager->registerExtension(function () {
$application = new \OCP\AppFramework\App('comments');
/** @var \OCA\Comments\Activity\Extension $extension */
$extension = $application->getContainer()->query('OCA\Comments\Activity\Extension');
return $extension;
});

$managerListener = function(\OCP\Comments\CommentsEvent $event) use ($activityManager) {
$managerListener = function (\OCP\Comments\CommentsEvent $event) use ($activityManager) {
$application = new \OCP\AppFramework\App('comments');
/** @var \OCA\Comments\Activity\Listener $listener */
$listener = $application->getContainer()->query('OCA\Comments\Activity\Listener');
Expand All @@ -53,8 +53,8 @@ function() {

$eventDispatcher->addListener(\OCP\Comments\CommentsEvent::EVENT_ADD, $managerListener);

$eventDispatcher->addListener(\OCP\Comments\CommentsEntityEvent::EVENT_ENTITY, function(\OCP\Comments\CommentsEntityEvent $event) {
$event->addEntityCollection('files', function($name) {
$eventDispatcher->addListener(\OCP\Comments\CommentsEntityEvent::EVENT_ENTITY, function (\OCP\Comments\CommentsEntityEvent $event) {
$event->addEntityCollection('files', function ($name) {
$nodes = \OC::$server->getUserFolder()->getById(\intval($name));
return !empty($nodes);
});
Expand Down
2 changes: 0 additions & 2 deletions apps/comments/lib/Activity/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ public function translate($app, $text, $params, $stripPath, $highlightParams, $l
* @return bool|string
*/
protected function translateShort($text, IL10N $l, array $params) {

switch ($text) {
case self::ADD_COMMENT_SUBJECT:
if ($this->authorIsCurrentUser($params[0])) {
Expand All @@ -172,7 +171,6 @@ protected function translateShort($text, IL10N $l, array $params) {
* @return bool|string
*/
protected function translateLong($text, IL10N $l, array $params) {

switch ($text) {
case self::ADD_COMMENT_SUBJECT:
if ($this->authorIsCurrentUser($params[0])) {
Expand Down
36 changes: 18 additions & 18 deletions apps/comments/lib/Dav/CommentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ public function __construct(
$this->logger = $logger;

$methods = \get_class_methods($this->comment);
$methods = \array_filter($methods, function($name){
$methods = \array_filter($methods, function ($name) {
return \strpos($name, 'get') === 0;
});
foreach($methods as $getter) {
foreach ($methods as $getter) {
$name = '{'.self::NS_OWNCLOUD.'}' . \lcfirst(\substr($getter, 3));
$this->properties[$name] = $getter;
}
Expand All @@ -95,7 +95,7 @@ public function __construct(
*
* @return array
*/
static public function getPropertyNames() {
public static function getPropertyNames() {
return [
'{http://owncloud.org/ns}id',
'{http://owncloud.org/ns}parentId',
Expand All @@ -117,8 +117,8 @@ static public function getPropertyNames() {

protected function checkWriteAccessOnComment() {
$user = $this->userSession->getUser();
if($this->comment->getActorType() !== 'users'
|| \is_null($user)
if ($this->comment->getActorType() !== 'users'
|| $user === null
|| $this->comment->getActorId() !== $user->getUID()
) {
throw new Forbidden('Only authors are allowed to edit their comment.');
Expand All @@ -130,7 +130,7 @@ protected function checkWriteAccessOnComment() {
*
* @return void
*/
function delete() {
public function delete() {
$this->checkWriteAccessOnComment();
$this->commentsManager->delete($this->comment->getId());
}
Expand All @@ -142,7 +142,7 @@ function delete() {
*
* @return string
*/
function getName() {
public function getName() {
return $this->comment->getId();
}

Expand All @@ -152,7 +152,7 @@ function getName() {
* @param string $name The new name
* @throws MethodNotAllowed
*/
function setName($name) {
public function setName($name) {
throw new MethodNotAllowed();
}

Expand All @@ -161,7 +161,7 @@ function setName($name) {
*
* @return int
*/
function getLastModified() {
public function getLastModified() {
return null;
}

Expand All @@ -181,7 +181,7 @@ public function updateComment($propertyValue) {
return true;
} catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'dav/comments']);
if($e instanceof MessageTooLongException) {
if ($e instanceof MessageTooLongException) {
$msg = 'Message exceeds allowed character limit of ';
throw new BadRequest($msg . IComment::MAX_MESSAGE_LENGTH, 0, $e);
}
Expand All @@ -201,7 +201,7 @@ public function updateComment($propertyValue) {
* @param PropPatch $propPatch
* @return void
*/
function propPatch(PropPatch $propPatch) {
public function propPatch(PropPatch $propPatch) {
// other properties than 'message' are read only
$propPatch->handle(self::PROPERTY_NAME_MESSAGE, [$this, 'updateComment']);
}
Expand All @@ -221,32 +221,32 @@ function propPatch(PropPatch $propPatch) {
* @param array $properties
* @return array
*/
function getProperties($properties) {
public function getProperties($properties) {
$properties = \array_keys($this->properties);

$result = [];
foreach($properties as $property) {
foreach ($properties as $property) {
$getter = $this->properties[$property];
if(\method_exists($this->comment, $getter)) {
if (\method_exists($this->comment, $getter)) {
$result[$property] = $this->comment->$getter();
}
}

if($this->comment->getActorType() === 'users') {
if ($this->comment->getActorType() === 'users') {
$user = $this->userManager->get($this->comment->getActorId());
$displayName = \is_null($user) ? null : $user->getDisplayName();
$displayName = $user === null ? null : $user->getDisplayName();
$result[self::PROPERTY_NAME_ACTOR_DISPLAYNAME] = $displayName;
}

$unread = null;
$user = $this->userSession->getUser();
if(!\is_null($user)) {
if ($user !== null) {
$readUntil = $this->commentsManager->getReadMark(
$this->comment->getObjectType(),
$this->comment->getObjectId(),
$user
);
if(\is_null($readUntil)) {
if ($readUntil === null) {
$unread = 'true';
} else {
$unread = $this->comment->getCreationDateTime() > $readUntil;
Expand Down
28 changes: 13 additions & 15 deletions apps/comments/lib/Dav/CommentsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public function __construct(ICommentsManager $commentsManager, IUserSession $use
* @param Server $server
* @return void
*/
function initialize(Server $server) {
public function initialize(Server $server) {
$this->server = $server;
if(\strpos($this->server->getRequestUri(), 'comments/') !== 0) {
if (\strpos($this->server->getRequestUri(), 'comments/') !== 0) {
return;
}

Expand All @@ -93,7 +93,7 @@ function initialize(Server $server) {

$this->server->xml->namespaceMap[self::NS_OWNCLOUD] = 'oc';

$this->server->xml->classMap['DateTime'] = function(Writer $writer, \DateTime $value) {
$this->server->xml->classMap['DateTime'] = function (Writer $writer, \DateTime $value) {
$writer->write(\Sabre\HTTP\toDate($value));
};

Expand Down Expand Up @@ -160,7 +160,7 @@ public function getSupportedReportSet($uri) {
*/
public function onReport($reportName, $report, $uri) {
$node = $this->server->tree->getNodeForPath($uri);
if(!$node instanceof EntityCollection || $reportName !== self::REPORT_NAME) {
if (!$node instanceof EntityCollection || $reportName !== self::REPORT_NAME) {
throw new ReportNotSupported();
}
$args = ['limit' => 0, 'offset' => 0, 'datetime' => null];
Expand All @@ -170,31 +170,30 @@ public function onReport($reportName, $report, $uri) {
$this::REPORT_PARAM_TIMESTAMP
];
$ns = '{' . $this::NS_OWNCLOUD . '}';
foreach($report as $parameter) {
if(!\in_array($parameter['name'], $acceptableParameters) || empty($parameter['value'])) {
foreach ($report as $parameter) {
if (!\in_array($parameter['name'], $acceptableParameters) || empty($parameter['value'])) {
continue;
}
$args[\str_replace($ns, '', $parameter['name'])] = $parameter['value'];
}

if(!\is_null($args['datetime'])) {
if ($args['datetime'] !== null) {
$args['datetime'] = new \DateTime($args['datetime']);
}

$results = $node->findChildren($args['limit'], $args['offset'], $args['datetime']);

$responses = [];
foreach($results as $node) {
foreach ($results as $node) {
$nodePath = $this->server->getRequestUri() . '/' . $node->comment->getId();
$resultSet = $this->server->getPropertiesForPath($nodePath, CommentNode::getPropertyNames());
if(isset($resultSet[0], $resultSet[0][200])) {
if (isset($resultSet[0], $resultSet[0][200])) {
$responses[] = new Response(
$this->server->getBaseUri() . $nodePath,
[200 => $resultSet[0][200]],
200
);
}

}

$xml = $this->server->xml->write(
Expand Down Expand Up @@ -230,13 +229,13 @@ private function createComment($objectType, $objectId, $data, $contentType = 'ap

$actorType = $data['actorType'];
$actorId = null;
if($actorType === 'users') {
if ($actorType === 'users') {
$user = $this->userSession->getUser();
if(!\is_null($user)) {
if ($user !== null) {
$actorId = $user->getUID();
}
}
if(\is_null($actorId)) {
if ($actorId === null) {
throw new BadRequest('Invalid actor "' . $actorType .'"');
}

Expand All @@ -250,8 +249,7 @@ private function createComment($objectType, $objectId, $data, $contentType = 'ap
throw new BadRequest('Invalid input values', 0, $e);
} catch (\OCP\Comments\MessageTooLongException $e) {
$msg = 'Message exceeds allowed character limit of ';
throw new BadRequest($msg . \OCP\Comments\IComment::MAX_MESSAGE_LENGTH, 0, $e);
throw new BadRequest($msg . \OCP\Comments\IComment::MAX_MESSAGE_LENGTH, 0, $e);
}
}

}
21 changes: 10 additions & 11 deletions apps/comments/lib/Dav/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function __construct(
IUserSession $userSession,
ILogger $logger
) {
foreach(['id', 'name'] as $property) {
foreach (['id', 'name'] as $property) {
$$property = \trim($$property);
if(empty($$property) || !\is_string($$property)) {
if (empty($$property) || !\is_string($$property)) {
throw new \InvalidArgumentException('"' . $property . '" parameter must be non-empty string');
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@ public function getId() {
* @return \Sabre\DAV\INode
* @throws NotFound
*/
function getChild($name) {
public function getChild($name) {
try {
$comment = $this->commentsManager->get($name);
return new CommentNode(
Expand All @@ -118,7 +118,7 @@ function getChild($name) {
*
* @return \Sabre\DAV\INode[]
*/
function getChildren() {
public function getChildren() {
return $this->findChildren();
}

Expand All @@ -131,10 +131,10 @@ function getChildren() {
* @param \DateTime|null $datetime
* @return CommentNode[]
*/
function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
public function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
$comments = $this->commentsManager->getForObject($this->name, $this->id, $limit, $offset, $datetime);
$result = [];
foreach($comments as $comment) {
foreach ($comments as $comment) {
$result[] = new CommentNode(
$this->commentsManager,
$comment,
Expand All @@ -152,7 +152,7 @@ function findChildren($limit = 0, $offset = 0, \DateTime $datetime = null) {
* @param string $name
* @return bool
*/
function childExists($name) {
public function childExists($name) {
try {
$this->commentsManager->get($name);
return true;
Expand All @@ -177,20 +177,19 @@ public function setReadMarker($value) {
/**
* @inheritdoc
*/
function propPatch(PropPatch $propPatch) {
public function propPatch(PropPatch $propPatch) {
$propPatch->handle(self::PROPERTY_NAME_READ_MARKER, [$this, 'setReadMarker']);
}

/**
* @inheritdoc
*/
function getProperties($properties) {
public function getProperties($properties) {
$marker = null;
$user = $this->userSession->getUser();
if(!\is_null($user)) {
if ($user !== null) {
$marker = $this->commentsManager->getReadMark($this->name, $this->id, $user);
}
return [self::PROPERTY_NAME_READ_MARKER => $marker];
}
}

11 changes: 5 additions & 6 deletions apps/comments/lib/Dav/EntityTypeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(
\Closure $childExistsFunction
) {
$name = \trim($name);
if(empty($name) || !\is_string($name)) {
if (empty($name) || !\is_string($name)) {
throw new \InvalidArgumentException('"name" parameter must be non-empty string');
}
$this->name = $name;
Expand All @@ -90,8 +90,8 @@ public function __construct(
* @return \Sabre\DAV\INode
* @throws NotFound
*/
function getChild($name) {
if(!$this->childExists($name)) {
public function getChild($name) {
if (!$this->childExists($name)) {
throw new NotFound('Entity does not exist or is not available');
}
return new EntityCollection(
Expand All @@ -110,7 +110,7 @@ function getChild($name) {
* @return \Sabre\DAV\INode[]
* @throws MethodNotAllowed
*/
function getChildren() {
public function getChildren() {
throw new MethodNotAllowed('No permission to list folder contents');
}

Expand All @@ -120,8 +120,7 @@ function getChildren() {
* @param string $name
* @return bool
*/
function childExists($name) {
public function childExists($name) {
return \call_user_func($this->childExistsFunction, $name);
}

}
Loading

0 comments on commit 5f0af49

Please sign in to comment.