Completed
Push — master ( b66ca6...b12848 )
by Samuel
15:09 queued 05:11
created

VariableNameModifier   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 10
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 10
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A modify() 0 8 2
1
<?php
2
3
namespace Efabrica\TranslationsAutomatization\TokenModifier;
4
5
use Efabrica\TranslationsAutomatization\Tokenizer\Token;
6
use Exception;
7
8
class VariableNameModifier extends TokenModifier
9
{
10
    protected function modify(Token $token): Token
11
    {
12
        preg_match('#\$(.*?)=#', $token->getOriginalBlock(), $matches);
13
        if (!isset($matches[1])) {
14
            throw new Exception('Cannot find variable name in ' . $token->getOriginalBlock());
15
        }
16
        $token->changeTranslationKey(trim($matches[1]));
17
        return $token;
18
    }
19
}
20