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

PhpUtils::getParsedFunctions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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