| Conditions | 3 |
| Paths | 3 |
| Total Lines | 22 |
| Code Lines | 14 |
| 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 | $validBlocks = [ |
||
| 72 | 4 | 'actions', |
|
| 73 | 'context', |
||
| 74 | 'divider', |
||
| 75 | 'file', |
||
| 76 | 'image', |
||
| 77 | 'input', |
||
| 78 | 'section', |
||
| 79 | ]; |
||
| 80 | |||
| 81 | 4 | if (!in_array($attributes['type'], $validBlocks)) { |
|
| 82 | 1 | throw new InvalidArgumentException('Block type must be one of: ' . implode(', ', $validBlocks) . '.'); |
|
| 83 | } |
||
| 84 | |||
| 85 | 3 | $className = __NAMESPACE__ . '\\Block\\' . ucfirst($attributes['type']); |
|
| 86 | 3 | return new $className($attributes); |
|
| 87 | } |
||
| 89 |