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

VariableNameModifier::modify()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 8
rs 10
cc 2
nc 2
nop 1
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