These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | /* |
||
6 | * This file is part of the Sonata Project package. |
||
7 | * |
||
8 | * (c) Thomas Rabaix <[email protected]> |
||
9 | * |
||
10 | * For the full copyright and license information, please view the LICENSE |
||
11 | * file that was distributed with this source code. |
||
12 | */ |
||
13 | |||
14 | namespace Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\DataFixtures\Phpcr; |
||
15 | |||
16 | use Doctrine\Common\DataFixtures\FixtureInterface; |
||
17 | use Doctrine\Common\Persistence\ObjectManager; |
||
18 | use PHPCR\Util\NodeHelper; |
||
19 | use Sonata\DoctrinePHPCRAdminBundle\Tests\Resources\Document\Content; |
||
20 | |||
21 | class LoadTreeData implements FixtureInterface |
||
22 | { |
||
23 | public function load(ObjectManager $manager): void |
||
24 | { |
||
25 | NodeHelper::createPath($manager->getPhpcrSession(), '/test'); |
||
26 | |||
27 | NodeHelper::createPath($manager->getPhpcrSession(), '/test/content'); |
||
0 ignored issues
–
show
|
|||
28 | NodeHelper::createPath($manager->getPhpcrSession(), '/test/routes'); |
||
29 | |||
30 | $contentRoot = $manager->find(null, '/test/content'); |
||
31 | $routeRoot = $manager->find(null, '/test/routes'); |
||
32 | |||
33 | $singleRoute = new Content(); |
||
34 | $singleRoute->setName('route-1'); |
||
35 | $singleRoute->setTitle('Route 1'); |
||
36 | $singleRoute->setParentDocument($routeRoot); |
||
37 | $manager->persist($singleRoute); |
||
38 | |||
39 | $routeAlikeA = new Content(); |
||
40 | $routeAlikeA->setName('route-2'); |
||
41 | $routeAlikeA->setTitle('Route 2'); |
||
42 | $routeAlikeA->setParentDocument($routeRoot); |
||
43 | $manager->persist($routeAlikeA); |
||
44 | |||
45 | $routeAlikeB = new Content(); |
||
46 | $routeAlikeB->setName('route-3'); |
||
47 | $routeAlikeB->setTitle('Route 3'); |
||
48 | $routeAlikeB->setParentDocument($routeRoot); |
||
49 | $manager->persist($routeAlikeB); |
||
50 | |||
51 | $child = new Content(); |
||
52 | $child->setName('child'); |
||
53 | $child->setTitle('Content Child'); |
||
54 | |||
55 | $content = new Content(); |
||
56 | $content->setName('content-1'); |
||
57 | $content->setTitle('Content 1'); |
||
58 | $content->setSingleRoute($singleRoute); |
||
59 | $content->addRoute($routeAlikeA); |
||
60 | $content->addRoute($routeAlikeB); |
||
61 | $content->setChild($child); |
||
62 | $content->setParentDocument($contentRoot); |
||
63 | $manager->persist($content); |
||
64 | |||
65 | $childA = new Content(); |
||
66 | $childA->setName('content-3'); |
||
67 | $childA->setTitle('Content Child A'); |
||
68 | |||
69 | $childB = new Content(); |
||
70 | $childB->setName('content-3'); |
||
71 | $childB->setTitle('Content Child B'); |
||
72 | |||
73 | $content = new Content(); |
||
74 | $content->setName('content-2'); |
||
75 | $content->setParentDocument($contentRoot); |
||
76 | $content->addChild($childA); |
||
77 | $content->addChild($childB); |
||
78 | $content->setTitle('Content 2'); |
||
79 | $manager->persist($content); |
||
80 | |||
81 | $manager->flush(); |
||
82 | } |
||
83 | } |
||
84 |
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: