Conditions | 16 |
Paths | 59 |
Total Lines | 63 |
Code Lines | 35 |
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 |
||
28 | public function __invoke(DocumentParsedEvent $e): void |
||
29 | { |
||
30 | /** @var string[] $excludedShortcodes */ |
||
31 | $excludedShortcodes = $this->config->get('exclude/shortcodes'); |
||
32 | |||
33 | /** @var ?int $presentation */ |
||
34 | $presentation = $this->config->get('presentation'); |
||
35 | |||
36 | // Ensure emojis are set to the correct stringable type. |
||
37 | foreach ($e->getDocument()->getNodes() as $node) { |
||
38 | if (! ($node instanceof Emoji)) { |
||
39 | continue; |
||
40 | } |
||
41 | |||
42 | $literal = null; |
||
43 | $type = $node->getParsedType(); |
||
44 | $configPath = 'convert.' . (EmojiConverterInterface::TYPES[$type] ?? ''); |
||
45 | |||
46 | /** @var ?int $conversionType */ |
||
47 | $conversionType = null; |
||
48 | |||
49 | if ($this->config->exists($configPath) && ($configType = (string) ($this->config->get($configPath) ?? ''))) { |
||
50 | $index = \array_search($configType, EmojiConverterInterface::TYPES, true); |
||
51 | if (\is_int($index)) { |
||
52 | $conversionType = $index; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | // If the conversion type isn't one of the core Lexer:TYPES, then do nothing. |
||
57 | // It should be handled by a different extension/processor. |
||
58 | if ($conversionType === null) { |
||
59 | continue; |
||
60 | } |
||
61 | |||
62 | switch ($conversionType) { |
||
63 | case EmojiLexer::T_EMOTICON: |
||
64 | $literal = $node->emoticon; |
||
65 | break; |
||
66 | |||
67 | case EmojiLexer::T_HTML_ENTITY: |
||
68 | $literal = $node->htmlEntity; |
||
69 | break; |
||
70 | |||
71 | case EmojiLexer::T_SHORTCODE: |
||
72 | if ($shortcode = $node->getShortcode($excludedShortcodes, true)) { |
||
73 | $literal = $shortcode; |
||
74 | } |
||
75 | |||
76 | break; |
||
77 | |||
78 | case EmojiLexer::T_TEXT: |
||
79 | case EmojiLexer::T_UNICODE: |
||
80 | if (($presentation ?? $node->type) === EmojibaseDatasetInterface::TEXT && $node->text) { |
||
81 | $literal = $node->text; |
||
82 | } else { |
||
83 | $literal = $node->emoji ?? $node->unicode; |
||
84 | } |
||
85 | |||
86 | break; |
||
87 | } |
||
88 | |||
89 | if ($literal !== null) { |
||
90 | $node->setContent($literal); |
||
91 | } |
||
100 |