fsi-open /
admin-bundle
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 | * (c) FSi sp. z o.o. <[email protected]> |
||
| 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 FSi\Bundle\AdminBundle\Doctrine\Admin; |
||
| 13 | |||
| 14 | use Doctrine\Common\Persistence\ManagerRegistry; |
||
| 15 | use Doctrine\Common\Persistence\ObjectManager; |
||
| 16 | use Doctrine\Common\Persistence\ObjectRepository; |
||
| 17 | use FSi\Bundle\AdminBundle\Exception\RuntimeException; |
||
| 18 | |||
| 19 | trait ElementImpl |
||
| 20 | { |
||
| 21 | /** |
||
| 22 | * @var ManagerRegistry |
||
| 23 | */ |
||
| 24 | protected $registry; |
||
| 25 | |||
| 26 | public function setManagerRegistry(ManagerRegistry $registry): void |
||
| 27 | { |
||
| 28 | $this->registry = $registry; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function getObjectManager(): ObjectManager |
||
| 32 | { |
||
| 33 | $om = $this->registry->getManagerForClass($this->getClassName()); |
||
| 34 | |||
| 35 | if (null === $om) { |
||
| 36 | throw new RuntimeException(sprintf( |
||
| 37 | 'Registry manager does\'t have manager for class "%s".', |
||
| 38 | $this->getClassName() |
||
|
0 ignored issues
–
show
|
|||
| 39 | )); |
||
| 40 | } |
||
| 41 | |||
| 42 | return $om; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getRepository(): ObjectRepository |
||
| 46 | { |
||
| 47 | return $this->getObjectManager()->getRepository($this->getClassName()); |
||
| 48 | } |
||
| 49 | } |
||
| 50 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.