Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Introduce phpstan #35774

Merged
merged 18 commits into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
dd88b09
added simple invocation methods to makefile
patrickjahns Jun 17, 2018
e2d1a87
run phpstan in drone
patrickjahns Jun 17, 2018
7a2efb0
fix case mismatches detected by phpstan
patrickjahns Jun 22, 2018
38041a4
fix acessing undefined propertoes
patrickjahns Jun 22, 2018
24a9b0d
Fix phpstan errors
DeepDiver1975 Oct 17, 2018
4b53120
Remove xcache remainings
DeepDiver1975 Oct 17, 2018
f801b6c
Ignore aws-sdk-php FooBar.php for phpstan
phil-davis Jul 7, 2019
3d35fb0
Revert constructor parameters InvalidStorage.php Temporary.php to mat…
phil-davis Jul 7, 2019
c8f9041
add phpstan extra autoload_directories for stable10
phil-davis Jul 7, 2019
11204bc
Fix throw PrivateKeyMissingException in apps/encryption/lib/Session.php
phil-davis Jul 7, 2019
90f5e81
declare in apps/files_external/lib/Lib/Storage/AmazonS3.php
phil-davis Jul 7, 2019
758a776
Fix 'Scanner::scan() invoked with 5 parameters, 1-4 required'
phil-davis Jul 7, 2019
fdff19f
Fix 'Class OCP\API does not have a constructor and must be instantiat…
phil-davis Jul 7, 2019
80486a7
Avoid 'Constructor of class OC\Files\External\InvalidStorage has an u…
phil-davis Jul 7, 2019
bb68154
Avoid 'Constructor of class OC\Files\Storage\Temporary has an unused …
phil-davis Jul 7, 2019
834814f
Fix 'Call to sprintf contains 1 placeholder, 2 values given'
phil-davis Jul 7, 2019
ebcbb3d
fix 'Class OC\AppFramework\Middleware\Security\Exceptions\NotAdminExc…
phil-davis Jul 7, 2019
1b368f7
Fix case of BackgroundJob call
phil-davis Jul 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this comes from the backport.
Similar to /build/phan.phar above it. these files should not even appear in the build directory these days - the tools are in vendor-bin

But we can remove these later. For now, this gets stable10 matching master

/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