Skip to content

Commit

Permalink
Merge pull request #35774 from owncloud/stable10-add-phpstan
Browse files Browse the repository at this point in the history
[stable10] Introduce phpstan
  • Loading branch information
DeepDiver1975 authored Jul 10, 2019
2 parents 79cd935 + 1b368f7 commit 2d2dbc1
Show file tree
Hide file tree
Showing 90 changed files with 265 additions and 208 deletions.
14 changes: 14 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,15 @@ pipeline:
matrix:
PRIMARY_OBJECTSTORE: files_primary_s3

phpstan:
image: owncloudci/php:${PHP_VERSION}
pull: true
commands:
- make test-php-phpstan
when:
matrix:
TEST_SUITE: phpstan

phpunit:
image: owncloudci/php:${PHP_VERSION}
pull: true
Expand Down Expand Up @@ -671,6 +680,11 @@ matrix:
- TEST_SUITE: phan
PHP_VERSION: 7.1

# phpstan
- TEST_SUITE: phpstan
PHP_VERSION: 7.1
INSTALL_SERVER: true

# Litmus
- PHP_VERSION: 7.1
USE_SERVER: true
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/build/composer.phar
/build/dist
/build/phan.phar
/build/phpstan.phar*
/core/vendor

# ignore all apps except core ones
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function () {
return $extension;
});

$managerListener = function (\OCP\Comments\CommentsEvent $event) use ($activityManager) {
$managerListener = function (\OCP\Comments\CommentsEvent $event) {
$application = new \OCP\AppFramework\App('comments');
/** @var \OCA\Comments\Activity\Listener $listener */
$listener = $application->getContainer()->query('OCA\Comments\Activity\Listener');
Expand Down
11 changes: 4 additions & 7 deletions apps/comments/lib/Dav/EntityCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\IProperties;
use Sabre\DAV\PropPatch;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class EntityCollection
Expand All @@ -46,15 +47,13 @@ class EntityCollection extends RootCollection implements IProperties {
/** @var string */
protected $id;

/** @var ILogger */
protected $logger;

/**
* @param string $id
* @param string $name
* @param ICommentsManager $commentsManager
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param EventDispatcherInterface $dispatcher
* @param ILogger $logger
*/
public function __construct(
Expand All @@ -63,8 +62,10 @@ public function __construct(
ICommentsManager $commentsManager,
IUserManager $userManager,
IUserSession $userSession,
EventDispatcherInterface $dispatcher,
ILogger $logger
) {
parent::__construct($commentsManager, $userManager, $userSession, $dispatcher, $logger);
foreach (['id', 'name'] as $property) {
$$property = \trim($$property);
if (empty($$property) || !\is_string($$property)) {
Expand All @@ -73,10 +74,6 @@ public function __construct(
}
$this->id = $id;
$this->name = $name;
$this->commentsManager = $commentsManager;
$this->logger = $logger;
$this->userManager = $userManager;
$this->userSession = $userSession;
}

/**
Expand Down
9 changes: 5 additions & 4 deletions apps/comments/lib/Dav/EntityTypeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\IUserSession;
use Sabre\DAV\Exception\MethodNotAllowed;
use Sabre\DAV\Exception\NotFound;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* Class EntityTypeCollection
Expand Down Expand Up @@ -57,6 +58,7 @@ class EntityTypeCollection extends RootCollection {
* @param ICommentsManager $commentsManager
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param EventDispatcherInterface $dispatcher
* @param ILogger $logger
* @param \Closure $childExistsFunction
*/
Expand All @@ -65,18 +67,16 @@ public function __construct(
ICommentsManager $commentsManager,
IUserManager $userManager,
IUserSession $userSession,
EventDispatcherInterface $dispatcher,
ILogger $logger,
\Closure $childExistsFunction
) {
$name = \trim($name);
if (empty($name) || !\is_string($name)) {
throw new \InvalidArgumentException('"name" parameter must be non-empty string');
}
parent::__construct($commentsManager, $userManager, $userSession, $dispatcher, $logger);
$this->name = $name;
$this->commentsManager = $commentsManager;
$this->logger = $logger;
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->childExistsFunction = $childExistsFunction;
}

Expand All @@ -100,6 +100,7 @@ public function getChild($name) {
$this->commentsManager,
$this->userManager,
$this->userSession,
$this->dispatcher,
$this->logger
);
}
Expand Down
1 change: 1 addition & 0 deletions apps/comments/lib/Dav/RootCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ protected function initCollections() {
$this->commentsManager,
$this->userManager,
$this->userSession,
$this->dispatcher,
$this->logger,
$entityExistsFunction
);
Expand Down
39 changes: 25 additions & 14 deletions apps/comments/tests/unit/Dav/EntityCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@

namespace OCA\DAV\Tests\unit\Comments;

use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCP\Comments\IComment;
use OCP\ILogger;
use OCP\IUserSession;
use OCP\IUserManager;
use OCP\Comments\ICommentsManager;

class EntityCollectionTest extends \Test\TestCase {

/** @var \OCP\Comments\ICommentsManager|\PHPUnit\Framework\MockObject\MockObject */
Expand All @@ -36,34 +43,38 @@ class EntityCollectionTest extends \Test\TestCase {
protected $collection;
/** @var \OCP\IUserSession|\PHPUnit\Framework\MockObject\MockObject */
protected $userSession;
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $dispatcher;

public function setUp() {
parent::setUp();

$this->commentsManager = $this->createMock('\OCP\Comments\ICommentsManager');
$this->userManager = $this->createMock('\OCP\IUserManager');
$this->userSession = $this->createMock('\OCP\IUserSession');
$this->logger = $this->createMock('\OCP\ILogger');
$this->commentsManager = $this->createMock(ICommentsManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->logger = $this->createMock(ILogger::class);
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);

$this->collection = new \OCA\Comments\Dav\EntityCollection(
'19',
'files',
$this->commentsManager,
$this->userManager,
$this->userSession,
$this->dispatcher,
$this->logger
);
}

public function testGetId() {
public function testGetId(): void {
$this->assertSame($this->collection->getId(), '19');
}

public function testGetChild() {
public function testGetChild(): void {
$this->commentsManager->expects($this->once())
->method('get')
->with('55')
->will($this->returnValue($this->createMock('\OCP\Comments\IComment')));
->will($this->returnValue($this->createMock(IComment::class)));

$node = $this->collection->getChild('55');
$this->assertInstanceOf(\OCA\Comments\Dav\CommentNode::class, $node);
Expand All @@ -72,7 +83,7 @@ public function testGetChild() {
/**
* @expectedException \Sabre\DAV\Exception\NotFound
*/
public function testGetChildException() {
public function testGetChildException(): void {
$this->commentsManager->expects($this->once())
->method('get')
->with('55')
Expand All @@ -81,36 +92,36 @@ public function testGetChildException() {
$this->collection->getChild('55');
}

public function testGetChildren() {
public function testGetChildren(): void {
$this->commentsManager->expects($this->once())
->method('getForObject')
->with('files', '19')
->will($this->returnValue([$this->createMock('\OCP\Comments\IComment')]));
->will($this->returnValue([$this->createMock(IComment::class)]));

$result = $this->collection->getChildren();

$this->assertSame(\count($result), 1);
$this->assertInstanceOf(\OCA\Comments\Dav\CommentNode::class, $result[0]);
}

public function testFindChildren() {
public function testFindChildren(): void {
$dt = new \DateTime('2016-01-10 18:48:00');
$this->commentsManager->expects($this->once())
->method('getForObject')
->with('files', '19', 5, 15, $dt)
->will($this->returnValue([$this->createMock('\OCP\Comments\IComment')]));
->will($this->returnValue([$this->createMock(IComment::class)]));

$result = $this->collection->findChildren(5, 15, $dt);

$this->assertSame(\count($result), 1);
$this->assertInstanceOf(\OCA\Comments\Dav\CommentNode::class, $result[0]);
}

public function testChildExistsTrue() {
public function testChildExistsTrue(): void {
$this->assertTrue($this->collection->childExists('44'));
}

public function testChildExistsFalse() {
public function testChildExistsFalse(): void {
$this->commentsManager->expects($this->once())
->method('get')
->with('44')
Expand Down
21 changes: 15 additions & 6 deletions apps/comments/tests/unit/Dav/EntityTypeCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@

namespace OCA\DAV\Tests\unit\Comments;

use OCA\Comments\Dav\EntityCollection as EntityCollectionImplemantation;
use OCA\Comments\Dav\EntityCollection as EntityCollectionImplementation;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use OCP\ILogger;
use OCP\IUserSession;
use OCP\IUserManager;
use OCP\Comments\ICommentsManager;

class EntityTypeCollectionTest extends \Test\TestCase {

Expand All @@ -40,14 +45,17 @@ class EntityTypeCollectionTest extends \Test\TestCase {
protected $userSession;

protected $childMap = [];
/** @var EventDispatcherInterface | \PHPUnit_Framework_MockObject_MockObject */
private $dispatcher;

public function setUp() {
parent::setUp();

$this->commentsManager = $this->createMock('\OCP\Comments\ICommentsManager');
$this->userManager = $this->createMock('\OCP\IUserManager');
$this->userSession = $this->createMock('\OCP\IUserSession');
$this->logger = $this->createMock('\OCP\ILogger');
$this->commentsManager = $this->createMock(ICommentsManager::class);
$this->userManager = $this->createMock(IUserManager::class);
$this->userSession = $this->createMock(IUserSession::class);
$this->logger = $this->createMock(ILogger::class);
$this->dispatcher = $this->createMock(EventDispatcherInterface::class);

$instance = $this;

Expand All @@ -56,6 +64,7 @@ public function setUp() {
$this->commentsManager,
$this->userManager,
$this->userSession,
$this->dispatcher,
$this->logger,
function ($child) use ($instance) {
return !empty($instance->childMap[$child]);
Expand All @@ -76,7 +85,7 @@ public function testGetChild() {
$this->childMap[17] = true;

$ec = $this->collection->getChild('17');
$this->assertInstanceOf(EntityCollectionImplemantation::class, $ec);
$this->assertInstanceOf(EntityCollectionImplementation::class, $ec);
}

/**
Expand Down
6 changes: 6 additions & 0 deletions apps/dav/lib/CalDAV/BirthdayService.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class BirthdayService {
/** @var GroupPrincipalBackend */
private $principalBackend;

/** @var CardDavBackend */
private $cardDavBackEnd;

/** @var CalDavBackend */
private $calDavBackEnd;

/**
* BirthdayService constructor.
*
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/CalendarHome.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function getChild($name) {
return new Outbox($this->principalInfo['uri']);
}
if ($name === 'notifications' && $this->caldavBackend instanceof NotificationSupport) {
return new \Sabre\CalDAv\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
return new \Sabre\CalDAV\Notifications\Collection($this->caldavBackend, $this->principalInfo['uri']);
}

// Calendars
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CalDAV/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function propFind(DAV\PropFind $propFind, DAV\INode $node) {
parent::propFind($propFind, $node);

if ($node instanceof Calendar && $node->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) {
$propFind->handle('{DAV:}share-access', function () use ($node) {
$propFind->handle('{DAV:}share-access', function () {
return new ShareAccess(DAV\Sharing\Plugin::ACCESS_NOACCESS);
});
}
Expand Down
3 changes: 3 additions & 0 deletions apps/dav/lib/CardDAV/ContactsManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@

class ContactsManager {

/** @var CardDavBackend */
private $backend;

/**
* ContactsManager constructor.
*
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CardDAV/ImageExportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function getPhoto(Card $node) {

$val = $photo->getValue();
if ($photo->getValueType() === 'URI') {
$parsed = \Sabre\URI\parse($val);
$parsed = \Sabre\Uri\parse($val);
//only allow data://
if ($parsed['scheme'] !== 'data') {
return false;
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/CardDAV/SyncService.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public function getLocalSystemAddressBook() {

public function syncInstance(\Closure $progressCallback = null) {
$systemAddressBook = $this->getLocalSystemAddressBook();
$this->userManager->callForAllUsers(function ($user) use ($systemAddressBook, $progressCallback) {
$this->userManager->callForAllUsers(function ($user) use ($progressCallback) {
$this->updateUser($user);
if ($progressCallback !== null) {
$progressCallback();
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function handleGetProperties(PropFind $propFind, \Sabre\DAV\INode $node)
}

if ($node instanceof \OCA\DAV\Connector\Sabre\Node) {
$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () use ($node) {
$propFind->handle(self::DATA_FINGERPRINT_PROPERTYNAME, function () {
return $this->config->getSystemValue('data-fingerprint', '');
});
}
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/Connector/Sabre/FilesReportPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public function onReport($reportName, $report, $uri) {
try {
$resultFileIds = $this->processFilterRules($filterRules);
} catch (TagNotFoundException $e) {
throw new PreconditionFailed('Cannot filter by non-existing tag', 0, $e);
throw new PreconditionFailed('Cannot filter by non-existing tag');
}

// pre-slice the results if needed for pagination to not waste
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

use OCP\IDBConnection;
use OCP\IUser;
use Sabre\Dav\Exception\Forbidden;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\Exception\ServiceUnavailable;
use Sabre\DAV\INode;
Expand Down
Loading

0 comments on commit 2d2dbc1

Please sign in to comment.