Test Failed
Push — main ( 67a638...1f412f )
by Guillaume
02:25
created

PhpUtils   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getParsedFunctions() 0 2 1
A parseFile() 0 8 2
1
<?php
2
3
namespace PHPMV\utils;
4
5
class PhpUtils {
6
	static private string $delimiter = '---';
7
	static private array $parsedFunctions = [];
8
9
	public static function parseFile(string $filename, string $extension): array {
10
		$pattern = '/' . self::$delimiter . '(.+?)'. self::$delimiter . '(.+?)' . self::$delimiter . 'end' . self::$delimiter . '/s';
11
		$templateString = \file_get_contents($filename . '.' . $extension, true);
12
		\preg_match_all($pattern, $templateString, $templateArray);
13
		for($i=0;$i<count($templateArray[0]);$i++){
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
14
			self::$parsedFunctions[$templateArray[1][$i]] = $templateArray[2][$i];
15
		}
16
		return $templateArray;
17
	}
18
19
	public static function getParsedFunctions():array {
20
		return self::$parsedFunctions;
21
	}
22
}
23
24