Total Complexity | 8 |
Total Lines | 86 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | abstract class AbstractStepTransformer |
||
8 | { |
||
9 | /** |
||
10 | * Steps that should be taken to transform the string from raw to end result. |
||
11 | * |
||
12 | * @return array |
||
13 | */ |
||
14 | abstract protected static function getTransformerSteps(); |
||
15 | |||
16 | /** |
||
17 | * Content to be parsed. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $content; |
||
22 | |||
23 | /** |
||
24 | * AbstractStep constructor. |
||
25 | * |
||
26 | * @param string $content content to be parsed |
||
27 | */ |
||
28 | public function __construct(string $content) |
||
29 | { |
||
30 | $this->content = $content; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Parse the content. |
||
35 | * |
||
36 | * @throws InvalidFormat |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | public function parse() |
||
57 | } |
||
58 | |||
59 | /** |
||
60 | * Call transformer method by it's partial name. |
||
61 | * |
||
62 | * @param string $name Transformer name |
||
63 | * |
||
64 | * @return string|array |
||
65 | */ |
||
66 | protected static function callTransformer($name, $content) |
||
67 | { |
||
68 | $transformer = static::getTransformerMethodName($name); |
||
69 | |||
70 | if(! method_exists(static::class, $transformer)) { |
||
71 | return $content; |
||
72 | } |
||
73 | |||
74 | return static::$transformer($content); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Get method name for transformer by it's partial name. |
||
79 | * |
||
80 | * @param string $name Transformer name |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | protected static function getTransformerMethodName($name) |
||
93 | } |
||
94 | } |
||
95 |