Skip to content

Commit 3f5fb52

Browse files
committed
Raise PHPStan's level from 2 to 3
1 parent be9bece commit 3f5fb52

16 files changed

+71
-36
lines changed

Document/AuthCodeManager.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ class AuthCodeManager extends BaseAuthCodeManager
3737

3838
public function __construct(DocumentManager $dm, $class)
3939
{
40+
// NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41+
/** @var DocumentRepository $repository */
42+
$repository = $dm->getRepository($class);
43+
4044
$this->dm = $dm;
41-
$this->repository = $dm->getRepository($class);
45+
$this->repository = $repository;
4246
$this->class = $class;
4347
}
4448

Document/ClientManager.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ class ClientManager extends BaseClientManager
3737

3838
public function __construct(DocumentManager $dm, $class)
3939
{
40+
// NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41+
/** @var DocumentRepository $repository */
42+
$repository = $dm->getRepository($class);
43+
4044
$this->dm = $dm;
41-
$this->repository = $dm->getRepository($class);
45+
$this->repository = $repository;
4246
$this->class = $class;
4347
}
4448

Document/TokenManager.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@ class TokenManager extends BaseTokenManager
3737

3838
public function __construct(DocumentManager $dm, $class)
3939
{
40+
// NOTE: bug in Doctrine, hinting DocumentRepository|ObjectRepository when only DocumentRepository is expected
41+
/** @var DocumentRepository $repository */
42+
$repository = $dm->getRepository($class);
43+
4044
$this->dm = $dm;
41-
$this->repository = $dm->getRepository($class);
45+
$this->repository = $repository;
4246
$this->class = $class;
4347
}
4448

Entity/ClientManager.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313

1414
namespace FOS\OAuthServerBundle\Entity;
1515

16-
use Doctrine\Common\Persistence\ObjectManager;
17-
use Doctrine\ORM\EntityManager;
16+
use Doctrine\ORM\EntityManagerInterface;
1817
use Doctrine\ORM\EntityRepository;
1918
use FOS\OAuthServerBundle\Model\ClientInterface;
2019
use FOS\OAuthServerBundle\Model\ClientManager as BaseClientManager;
2120

2221
class ClientManager extends BaseClientManager
2322
{
2423
/**
25-
* @var EntityManager
24+
* @var EntityManagerInterface
2625
*/
2726
protected $em;
2827

@@ -36,10 +35,14 @@ class ClientManager extends BaseClientManager
3635
*/
3736
protected $class;
3837

39-
public function __construct(ObjectManager $em, $class)
38+
public function __construct(EntityManagerInterface $em, $class)
4039
{
40+
// NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
41+
/** @var EntityRepository $repository */
42+
$repository = $em->getRepository($class);
43+
4144
$this->em = $em;
42-
$this->repository = $em->getRepository($class);
45+
$this->repository = $repository;
4346
$this->class = $class;
4447
}
4548

Entity/TokenManager.php

+8-5
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,15 @@
1313

1414
namespace FOS\OAuthServerBundle\Entity;
1515

16-
use Doctrine\Common\Persistence\ObjectManager;
17-
use Doctrine\ORM\EntityManager;
16+
use Doctrine\ORM\EntityManagerInterface;
1817
use Doctrine\ORM\EntityRepository;
1918
use FOS\OAuthServerBundle\Model\TokenInterface;
2019
use FOS\OAuthServerBundle\Model\TokenManager as BaseTokenManager;
2120

2221
class TokenManager extends BaseTokenManager
2322
{
2423
/**
25-
* @var EntityManager
24+
* @var EntityManagerInterface
2625
*/
2726
protected $em;
2827

@@ -36,10 +35,14 @@ class TokenManager extends BaseTokenManager
3635
*/
3736
protected $class;
3837

39-
public function __construct(ObjectManager $em, $class)
38+
public function __construct(EntityManagerInterface $em, $class)
4039
{
40+
// NOTE: bug in Doctrine, hinting EntityRepository|ObjectRepository when only EntityRepository is expected
41+
/** @var EntityRepository $repository */
42+
$repository = $em->getRepository($class);
43+
4144
$this->em = $em;
42-
$this->repository = $em->getRepository($class);
45+
$this->repository = $repository;
4346
$this->class = $class;
4447
}
4548

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ ci: cs-full-check phpstan phpunit-coverage
66
lint: cs-full-check phpstan
77

88
phpstan:
9-
sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon --level 2 ."
9+
sh -c "${QA_DOCKER_COMMAND} phpstan analyse --configuration phpstan.neon --level 3 ."
1010

1111
cs:
1212
sh -c "${QA_DOCKER_COMMAND} php-cs-fixer fix -vvv --diff"

Model/ClientManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function createClient()
3131
public function findClientByPublicId($publicId)
3232
{
3333
if (false === $pos = mb_strpos($publicId, '_')) {
34-
return;
34+
return null;
3535
}
3636

3737
$id = mb_substr($publicId, 0, $pos);

Model/ClientManagerInterface.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public function createClient();
2626
public function getClass();
2727

2828
/**
29-
* @return ClientInterface
29+
* @return null|ClientInterface
3030
*/
3131
public function findClientBy(array $criteria);
3232

3333
/**
3434
* @param mixed $publicId
3535
*
36-
* @return ClientInterface
36+
* @return null|ClientInterface
3737
*/
3838
public function findClientByPublicId($publicId);
3939

Security/Authentication/Provider/OAuthProvider.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,15 @@ public function __construct(UserProviderInterface $userProvider, OAuth2 $serverS
5959
/**
6060
* @param OAuthToken&TokenInterface $token
6161
*
62-
* @return OAuthToken
62+
* @return null|OAuthToken
6363
*/
6464
public function authenticate(TokenInterface $token)
6565
{
6666
if (!$this->supports($token)) {
67-
return;
67+
// note: since strict types in PHP 7, return; and return null; are not the same
68+
// Symfony's interface says to "never return null", but return; is still technically null
69+
// PHPStan treats return; as return (void);
70+
return null;
6871
}
6972

7073
try {

Tests/Entity/TokenManagerTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace FOS\OAuthServerBundle\Tests\Entity;
1515

1616
use Doctrine\ORM\AbstractQuery;
17+
use Doctrine\ORM\EntityManager;
1718
use Doctrine\ORM\EntityManagerInterface;
1819
use Doctrine\ORM\EntityRepository;
1920
use Doctrine\ORM\QueryBuilder;
@@ -53,11 +54,11 @@ class TokenManagerTest extends \PHPUnit\Framework\TestCase
5354
public function setUp()
5455
{
5556
$this->className = AccessToken::class;
56-
$this->repository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')
57+
$this->repository = $this->getMockBuilder(EntityRepository::class)
5758
->disableOriginalConstructor()
5859
->getMock()
5960
;
60-
$this->entityManager = $this->getMockBuilder('Doctrine\ORM\EntityManager')
61+
$this->entityManager = $this->getMockBuilder(EntityManager::class)
6162
->disableOriginalConstructor()
6263
->getMock()
6364
;

Tests/Form/Handler/AuthorizeFormHandlerTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public function setUp()
8989
$this->instance = new AuthorizeFormHandler($this->form, $this->request);
9090
$this->instance->setContainer($this->container);
9191

92+
$_GET = [];
93+
9294
parent::setUp();
9395
}
9496

Tests/Functional/BootTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function testBoot($env)
2424
{
2525
$this->markTestIncomplete('Issue with Stopwatch component');
2626

27-
$kernel = $this->createKernel(['env' => $env]);
27+
$kernel = static::createKernel(['env' => $env]);
2828
$kernel->boot();
2929
}
3030

Tests/Functional/TestCase.php

+6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@
1515

1616
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
1717
use Symfony\Component\Filesystem\Filesystem;
18+
use Symfony\Component\HttpKernel\KernelInterface;
1819

1920
abstract class TestCase extends WebTestCase
2021
{
22+
/**
23+
* @var null|KernelInterface
24+
*/
25+
protected static $kernel;
26+
2127
protected function setUp()
2228
{
2329
$fs = new Filesystem();

Tests/Security/Authentication/Provider/OAuthProviderTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class OAuthProviderTest extends \PHPUnit\Framework\TestCase
3535
protected $userProvider;
3636

3737
/**
38-
* @var \PHPUnit_Framework_MockObject_MockObject|OAuthProvider
38+
* @var OAuthProvider
3939
*/
4040
protected $provider;
4141

composer.json

+16-13
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,29 @@
1717
],
1818
"require": {
1919
"php": "^7.1",
20+
"alcaeus/mongo-php-adapter": "^1.1",
2021
"friendsofsymfony/oauth2-php": "~1.1",
21-
"symfony/framework-bundle": "~3.0|^4.0",
22-
"symfony/security-bundle": "~3.0|^4.0",
23-
"symfony/dependency-injection": "^2.8|~3.0|^4.0"
22+
"symfony/dependency-injection": "~3.0|~4.0",
23+
"symfony/framework-bundle": "~3.0|~4.0",
24+
"symfony/security-bundle": "~3.0|~4.0"
2425
},
2526
"require-dev": {
2627
"doctrine/doctrine-bundle": "~1.0",
2728
"doctrine/mongodb-odm": "~1.0",
2829
"doctrine/orm": "~2.2",
2930
"phing/phing": "~2.4",
30-
"php-mock/php-mock-phpunit": "^1.1",
31-
"phpunit/phpunit": "~4.8|~5.0",
32-
"propel/propel1": "^1.6.5",
33-
"symfony/class-loader": "~3.0|^4.0",
34-
"symfony/console": "~3.0|^4.0",
35-
"symfony/form": "~3.0|^4.0",
36-
"symfony/phpunit-bridge": "~3.0|^4.0",
37-
"symfony/templating": "~3.0|^4.0",
38-
"symfony/yaml": "~3.0|^4.0",
39-
"willdurand/propel-typehintable-behavior": "^1.0.4"
31+
"php-mock/php-mock-phpunit": "~1.0|~2.0",
32+
"phpstan/phpstan-phpunit": "~0.9",
33+
"phpstan/phpstan-shim": "~0.9",
34+
"phpunit/phpunit": "~5.0|~6.0",
35+
"propel/propel1": "~1.6",
36+
"symfony/class-loader": "~3.0|~4.0",
37+
"symfony/console": "~3.0|~4.0",
38+
"symfony/form": "~3.0|~4.0",
39+
"symfony/phpunit-bridge": "~3.0|~4.0",
40+
"symfony/templating": "~3.0|~4.0",
41+
"symfony/yaml": "~3.0|~4.0",
42+
"willdurand/propel-typehintable-behavior": "~1.0"
4043
},
4144
"suggest": {
4245
"doctrine/doctrine-bundle": "*",

phpstan.neon

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
includes:
2+
- vendor/phpstan/phpstan-phpunit/extension.neon
13
parameters:
24
autoload_files:
35
- vendor/autoload.php

0 commit comments

Comments
 (0)