| Conditions | 7 |
| Paths | 6 |
| Total Lines | 33 |
| Code Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | protected function fixTemplates($mapper) |
||
| 25 | { |
||
| 26 | $blast = $this->getConfigurationPool()->getContainer()->getParameter('blast'); |
||
|
|
|||
| 27 | if (!isset($blast['configuration']) && isset($blast['configuration']['templates'])) { |
||
| 28 | return $this; |
||
| 29 | } |
||
| 30 | |||
| 31 | $mapping = [ |
||
| 32 | 'ShowMapper' => 'show', |
||
| 33 | 'ListMapper' => 'list', |
||
| 34 | ]; |
||
| 35 | $rc = new \ReflectionClass($mapper); |
||
| 36 | if (!isset($mapping[$rc->getShortName()])) { |
||
| 37 | return $this; |
||
| 38 | } |
||
| 39 | |||
| 40 | $mapType = $mapping[$rc->getShortName()]; |
||
| 41 | if (!isset($blast['configuration']['templates'][$mapType])) { |
||
| 42 | return $this; |
||
| 43 | } |
||
| 44 | |||
| 45 | // get back the new templates |
||
| 46 | $templates = $blast['configuration']['templates'][$mapType]; |
||
| 47 | |||
| 48 | // checks if something has to be done |
||
| 49 | foreach ($this->{$mapType . 'FieldDescriptions'} as $fd) { |
||
| 50 | if (isset($templates[$fd->getType()])) { |
||
| 51 | $fd->setTemplate($templates[$fd->getType()]); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | return $this; |
||
| 56 | } |
||
| 57 | } |
||
| 58 |
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.