These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Symfony CMF package. |
||
5 | * |
||
6 | * (c) 2011-2017 Symfony CMF |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\DataFixtures\Phpcr; |
||
13 | |||
14 | use Doctrine\Common\DataFixtures\FixtureInterface; |
||
15 | use Doctrine\Common\Persistence\ObjectManager; |
||
16 | use PHPCR\Util\NodeHelper; |
||
17 | use Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content; |
||
18 | |||
19 | class LoadTreeData implements FixtureInterface |
||
20 | { |
||
21 | public function load(ObjectManager $manager) |
||
22 | { |
||
23 | NodeHelper::createPath($manager->getPhpcrSession(), '/test'); |
||
0 ignored issues
–
show
|
|||
24 | |||
25 | NodeHelper::createPath($manager->getPhpcrSession(), '/test/content'); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Doctrine\Common\Persistence\ObjectManager as the method getPhpcrSession() does only exist in the following implementations of said interface: Doctrine\ODM\PHPCR\Decor...ocumentManagerDecorator , Doctrine\ODM\PHPCR\DocumentManager , Doctrine\Tests\ODM\PHPCR...ManagerGetClassMetadata .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
26 | NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes'); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Doctrine\Common\Persistence\ObjectManager as the method getPhpcrSession() does only exist in the following implementations of said interface: Doctrine\ODM\PHPCR\Decor...ocumentManagerDecorator , Doctrine\ODM\PHPCR\DocumentManager , Doctrine\Tests\ODM\PHPCR...ManagerGetClassMetadata .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
27 | |||
28 | $contentRoot = $manager->find(null, '/test/content'); |
||
29 | $routeRoot = $manager->find(null, '/test/routes'); |
||
30 | |||
31 | $singleRoute = new Content(); |
||
32 | $singleRoute->setName('route-1'); |
||
33 | $singleRoute->setTitle('Route 1'); |
||
34 | $singleRoute->setParentDocument($routeRoot); |
||
35 | $manager->persist($singleRoute); |
||
36 | |||
37 | $routeAlikeA = new Content(); |
||
38 | $routeAlikeA->setName('route-2'); |
||
39 | $routeAlikeA->setTitle('Route 2'); |
||
40 | $routeAlikeA->setParentDocument($routeRoot); |
||
41 | $manager->persist($routeAlikeA); |
||
42 | |||
43 | $routeAlikeB = new Content(); |
||
44 | $routeAlikeB->setName('route-3'); |
||
45 | $routeAlikeB->setTitle('Route 3'); |
||
46 | $routeAlikeB->setParentDocument($routeRoot); |
||
47 | $manager->persist($routeAlikeB); |
||
48 | |||
49 | $child = new Content(); |
||
50 | $child->setName('child'); |
||
51 | $child->setTitle('Content Child'); |
||
52 | |||
53 | $content = new Content(); |
||
54 | $content->setName('content-1'); |
||
55 | $content->setTitle('Content 1'); |
||
56 | $content->setSingleRoute($singleRoute); |
||
57 | $content->addRoute($routeAlikeA); |
||
58 | $content->addRoute($routeAlikeB); |
||
59 | $content->setChild($child); |
||
60 | $content->setParentDocument($contentRoot); |
||
61 | $manager->persist($content); |
||
62 | |||
63 | $childA = new Content(); |
||
64 | $childA->setName('content-3'); |
||
65 | $childA->setTitle('Content Child A'); |
||
66 | |||
67 | $childB = new Content(); |
||
68 | $childB->setName('content-3'); |
||
69 | $childB->setTitle('Content Child B'); |
||
70 | |||
71 | $content = new Content(); |
||
72 | $content->setName('content-2'); |
||
73 | $content->setParentDocument($contentRoot); |
||
74 | $content->addChild($childA); |
||
75 | $content->addChild($childB); |
||
76 | $content->setTitle('Content 2'); |
||
77 | $manager->persist($content); |
||
78 | |||
79 | $manager->flush(); |
||
80 | } |
||
81 | } |
||
82 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: