PhpUtils   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 6
Bugs 1 Features 1
Metric Value
eloc 15
c 6
b 1
f 1
dl 0
loc 26
ccs 15
cts 15
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parseFile() 0 9 2
A importFromFile() 0 2 1
A getParsedJs() 0 7 2
1
<?php
2
3
namespace PHPMV\utils;
4
5
/**
6
 * Some php utilities.
7
 *
8
 * PHPMV\utilsPhpUtils
9
 * This class is part of php-vuejs
10
 *
11
 * @author jguillaumesio
12
 * @version 1.0.0
13
 * @package PHPMV\utils
14
 */
15
16
class PhpUtils {
17
	static private string $delimiter = '-';
18
	static private array $parsedJs = [];
19
20 2
	public static function importFromFile(string $filename, string $extension): string {
21 2
		return \str_replace(["\n","\r","\t"],"",\file_get_contents("$filename.$extension", true));
22
	}
23
24 1
	public static function parseFile(string $filename, string $extension): array {
25 1
		$pattern = '/\/\/' . self::$delimiter . '{3,}(.+?)' . self::$delimiter . '{3,}(.+?)\/\/' . self::$delimiter . '{3,}end' . self::$delimiter . '{3,}/s';
26 1
		$templateString = self::importFromFile($filename, $extension);
27 1
		\preg_match_all($pattern, $templateString, $templateArray);
28 1
		$iterationNumber = \count($templateArray[0]);
29 1
		for ($i = 0; $i < $iterationNumber; $i++) {
30 1
			self::$parsedJs[$templateArray[1][$i]] = $templateArray[2][$i];
31
		}
32 1
		return $templateArray;
33
	}
34
35 1
	public static function getParsedJs(string $name,array $variables = []): string {
36 1
		$element=self::$parsedJs[$name];
37 1
		foreach($variables as $key => $value){
38 1
			$element = \str_replace("{{ $key }}",$value, $element);
39
		}
40
41 1
		return $element;
42
	}
43
}
44