Transform   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 17
c 2
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A normalize() 0 22 4
1
<?php
2
3
declare(strict_types=1);
4
/**
5
 * Transform class.
6
 *
7
 * @package   YetiForcePDF\Style\Normalizer
8
 *
9
 * @copyright YetiForce Sp. z o.o
10
 * @license   MIT
11
 * @author    Rafal Pospiech <[email protected]>
12
 */
13
14
namespace YetiForcePDF\Style\Normalizer;
15
16
/**
17
 * Class Transform.
18
 */
19
class Transform extends Normalizer
20
{
21
	public function normalize($ruleValue, string $ruleName = ''): array
22
	{
23
		if (null !== $this->normalized) {
24
			return $this->normalized;
25
		}
26
		$normalized = [
27
			'transform' => [],
28
		];
29
		$operations = preg_split('/\s+/i', $ruleValue);
30
		foreach ($operations as $operation) {
31
			$matches = [];
32
			preg_match('/(rotate|scale|translate)\(([0-9]+)([a-z]+)?\)/i', $operation, $matches);
33
			$normalizerName = static::getNormalizerClassName('transform-' . $matches[1]);
34
			$normalizer = (new $normalizerName())
35
				->setDocument($this->document)
36
				->setStyle($this->style)
37
				->init();
38
			foreach ($normalizer->normalize($matches[2], $matches[1]) as $name => $value) {
39
				$normalized['transform'][] = [$name, $value];
40
			}
41
		}
42
		return $normalized;
43
	}
44
}
45