Conditions | 4 |
Paths | 5 |
Total Lines | 65 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
52 | public function construct(ConstructEvent $event) |
||
53 | { |
||
54 | if ($event->getTwig()->hasExtension(StringLoaderExtension::class)) { |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | // Twig core extensions |
||
59 | $event->getTwig()->addExtension(new StringLoaderExtension()); |
||
60 | $event->getTwig()->addExtension(new DebugExtension()); |
||
61 | |||
62 | // CakePHP bridging extensions |
||
63 | $event->getTwig()->addExtension(new Extension\I18n()); |
||
64 | $event->getTwig()->addExtension(new Extension\Time()); |
||
65 | $event->getTwig()->addExtension(new Extension\Basic()); |
||
66 | $event->getTwig()->addExtension(new Extension\Number()); |
||
67 | $event->getTwig()->addExtension(new Extension\Utils()); |
||
68 | $event->getTwig()->addExtension(new Extension\Arrays()); |
||
69 | $event->getTwig()->addExtension(new Extension\Strings()); |
||
70 | $event->getTwig()->addExtension(new Extension\Inflector()); |
||
71 | |||
72 | if ( |
||
73 | !Configure::check('WyriHaximus.TwigView.flags.potentialDangerous') || |
||
74 | ( |
||
75 | Configure::check('WyriHaximus.TwigView.flags.potentialDangerous') && |
||
76 | Configure::read('WyriHaximus.TwigView.flags.potentialDangerous') === true |
||
77 | ) |
||
78 | ) { |
||
79 | $event->getTwig()->addExtension(new Extension\PotentialDangerous()); |
||
80 | } |
||
81 | |||
82 | // Markdown extension |
||
83 | if ( |
||
84 | Configure::check('WyriHaximus.TwigView.markdown.engine') && |
||
85 | Configure::read('WyriHaximus.TwigView.markdown.engine') instanceof MarkdownInterface |
||
86 | ) { |
||
87 | $engine = Configure::read('WyriHaximus.TwigView.markdown.engine'); |
||
88 | $event->getTwig()->addExtension(new MarkdownExtension()); |
||
89 | |||
90 | $event->getTwig()->addRuntimeLoader(new class ($engine) implements RuntimeLoaderInterface { |
||
91 | /** |
||
92 | * @var \Twig\Extra\Markdown\MarkdownInterface |
||
93 | */ |
||
94 | private $engine; |
||
95 | |||
96 | public function __construct(MarkdownInterface $engine) |
||
97 | { |
||
98 | $this->engine = $engine; |
||
99 | } |
||
100 | |||
101 | public function load($class) |
||
102 | { |
||
103 | if ($class === MarkdownRuntime::class) { |
||
104 | return new MarkdownRuntime($this->engine); |
||
105 | } |
||
106 | } |
||
107 | }); |
||
108 | } |
||
109 | |||
110 | // jasny/twig-extensions |
||
111 | $event->getTwig()->addExtension(new DateExtension()); |
||
112 | $event->getTwig()->addExtension(new PcreExtension()); |
||
113 | $event->getTwig()->addExtension(new TextExtension()); |
||
114 | $event->getTwig()->addExtension(new ArrayExtension()); |
||
115 | // @codingStandardsIgnoreEnd |
||
116 | } |
||
117 | } |
||
118 |