| Conditions | 3 |
| Paths | 3 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 8 |
| CRAP Score | 3 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 65 | 5 | public static function factory(array $attributes) |
|
| 66 | { |
||
| 67 | 5 | if ( ! isset($attributes['type'])) { |
|
| 68 | 1 | throw new InvalidArgumentException('Cannot create Block without a type attribute'); |
|
| 69 | } |
||
| 70 | |||
| 71 | 4 | $validBlocks = [ |
|
| 72 | 'actions', |
||
| 73 | 'context', |
||
| 74 | 'divider', |
||
| 75 | 'file', |
||
| 76 | 'header', |
||
| 77 | 'image', |
||
| 78 | 'input', |
||
| 79 | 'section', |
||
| 80 | ]; |
||
| 81 | |||
| 82 | 4 | if ( ! in_array($attributes['type'], $validBlocks)) { |
|
| 83 | 1 | throw new InvalidArgumentException('Block type must be one of: '.implode(', ', $validBlocks).'.'); |
|
| 84 | } |
||
| 85 | |||
| 86 | 3 | $className = __NAMESPACE__.'\\Block\\'.ucfirst($attributes['type']); |
|
| 87 | |||
| 88 | 3 | return new $className($attributes); |
|
| 89 | } |
||
| 91 |