Skip to content

Commit

Permalink
apply cs fixer automatic fixes to stable10 code
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-davis committed Jul 21, 2018
1 parent 088cd0d commit 3bff5c2
Show file tree
Hide file tree
Showing 1,626 changed files with 13,320 additions and 15,675 deletions.
12 changes: 6 additions & 6 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,9 +53,9 @@ 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) {
$nodes = \OC::$server->getUserFolder()->getById(intval($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);
});
});
10 changes: 4 additions & 6 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 All @@ -194,7 +192,7 @@ protected function translateLong($text, IL10N $l, array $params) {
*/
protected function authorIsCurrentUser($user) {
try {
return strip_tags($user) === $this->activityManager->getCurrentUserId();
return \strip_tags($user) === $this->activityManager->getCurrentUserId();
} catch (\UnexpectedValueException $e) {
return false;
}
Expand Down Expand Up @@ -279,7 +277,7 @@ public function filterNotificationTypes($types, $filter) {
if ($filter === self::APP_NAME) {
return [self::APP_NAME];
}
if (in_array($filter, ['all', 'by', 'self', 'filter'])) {
if (\in_array($filter, ['all', 'by', 'self', 'filter'])) {
$types[] = self::APP_NAME;
return $types;
}
Expand All @@ -304,11 +302,11 @@ public function getQueryForFilter($filter) {
* @return string
*/
protected function convertParameterToComment($parameter) {
if (preg_match('/^\<parameter\>(\d*)\<\/parameter\>$/', $parameter, $matches)) {
if (\preg_match('/^\<parameter\>(\d*)\<\/parameter\>$/', $parameter, $matches)) {
try {
$comment = $this->commentsManager->get((int) $matches[1]);
$message = $comment->getMessage();
$message = str_replace("\n", '<br />', str_replace(['<', '>'], ['&lt;', '&gt;'], $message));
$message = \str_replace("\n", '<br />', \str_replace(['<', '>'], ['&lt;', '&gt;'], $message));
return $message;
} catch (NotFoundException $e) {
return '';
Expand Down
10 changes: 5 additions & 5 deletions apps/comments/lib/Activity/Listener.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct(IManager $activityManager,
*/
public function commentEvent(CommentsEvent $event) {
if ($event->getComment()->getObjectType() !== 'files'
|| !in_array($event->getEvent(), [CommentsEvent::EVENT_ADD])
|| !\in_array($event->getEvent(), [CommentsEvent::EVENT_ADD])
|| !$this->appManager->isInstalled('activity')) {
// Comment not for file, not adding a comment or no activity-app enabled (save the energy)
return;
Expand All @@ -89,13 +89,13 @@ public function commentEvent(CommentsEvent $event) {
$nodes = $ownerFolder->getById($event->getComment()->getObjectId());
if (!empty($nodes)) {
/** @var Node $node */
$node = array_shift($nodes);
$node = \array_shift($nodes);
$path = $node->getPath();
if (strpos($path, '/' . $owner . '/files/') === 0) {
$path = substr($path, strlen('/' . $owner . '/files'));
if (\strpos($path, '/' . $owner . '/files/') === 0) {
$path = \substr($path, \strlen('/' . $owner . '/files'));
}
// Get all users that have access to the mount point
$users = array_merge($users, Share::getUsersSharingFile($path, $owner, true, true));
$users = \array_merge($users, Share::getUsersSharingFile($path, $owner, true, true));
}
}

Expand Down
45 changes: 22 additions & 23 deletions apps/comments/lib/Dav/CommentNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace OCA\Comments\Dav;


use OCP\Comments\IComment;
use OCP\Comments\ICommentsManager;
use OCP\Comments\MessageTooLongException;
Expand Down Expand Up @@ -79,12 +78,12 @@ public function __construct(
$this->comment = $comment;
$this->logger = $logger;

$methods = get_class_methods($this->comment);
$methods = array_filter($methods, function($name){
return strpos($name, 'get') === 0;
$methods = \get_class_methods($this->comment);
$methods = \array_filter($methods, function ($name) {
return \strpos($name, 'get') === 0;
});
foreach($methods as $getter) {
$name = '{'.self::NS_OWNCLOUD.'}' . lcfirst(substr($getter, 3));
foreach ($methods as $getter) {
$name = '{'.self::NS_OWNCLOUD.'}' . \lcfirst(\substr($getter, 3));
$this->properties[$name] = $getter;
}
$this->userManager = $userManager;
Expand All @@ -96,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 @@ -118,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 @@ -131,7 +130,7 @@ protected function checkWriteAccessOnComment() {
*
* @return void
*/
function delete() {
public function delete() {
$this->checkWriteAccessOnComment();
$this->commentsManager->delete($this->comment->getId());
}
Expand All @@ -143,7 +142,7 @@ function delete() {
*
* @return string
*/
function getName() {
public function getName() {
return $this->comment->getId();
}

Expand All @@ -153,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 @@ -162,7 +161,7 @@ function setName($name) {
*
* @return int
*/
function getLastModified() {
public function getLastModified() {
return null;
}

Expand All @@ -182,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 @@ -202,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 @@ -222,32 +221,32 @@ function propPatch(PropPatch $propPatch) {
* @param array $properties
* @return array
*/
function getProperties($properties) {
$properties = array_keys($this->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
38 changes: 17 additions & 21 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 @@ -127,7 +127,7 @@ public function httpPost(RequestInterface $request, ResponseInterface $response)
// having their own comments marked as unread
$node->setReadMarker(null);

$url = rtrim($request->getUrl(), '/') . '/' . urlencode($comment->getId());
$url = \rtrim($request->getUrl(), '/') . '/' . \urlencode($comment->getId());

$response->setHeader('Content-Location', $url);

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'];
$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]) && isset($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 @@ -222,21 +221,21 @@ public function onReport($reportName, $report, $uri) {
* @throws UnsupportedMediaType if the content type is not supported
*/
private function createComment($objectType, $objectId, $data, $contentType = 'application/json') {
if (explode(';', $contentType)[0] === 'application/json') {
$data = json_decode($data, true);
if (\explode(';', $contentType)[0] === 'application/json') {
$data = \json_decode($data, true);
} else {
throw new UnsupportedMediaType();
}

$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,10 +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);
}
}



}
Loading

0 comments on commit 3bff5c2

Please sign in to comment.