Test Failed
Push — main ( 1f412f...1c4e95 )
by Guillaume
03:37
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 $parsedJs = [];
8
9
	public static function importJsFromFile(string $filename): string {
10
		return \file_get_contents($filename . '.js', true);
11
	}
12
13
	public static function parseFile(string $filename, string $extension): array {
14
		$pattern = '/' . self::$delimiter . '(.+?)' . self::$delimiter . '(.+?)' . self::$delimiter . 'end' . self::$delimiter . '/s';
15
		$templateString = self::importFile($filename, $extension);
0 ignored issues
show
Bug introduced by
The method importFile() does not exist on PHPMV\utils\PhpUtils. Did you maybe mean importJsFromFile()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

15
		/** @scrutinizer ignore-call */ 
16
  $templateString = self::importFile($filename, $extension);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
16
		\preg_match_all($pattern, $templateString, $templateArray);
17
		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...
18
			self::$parsedJs[$templateArray[1][$i]] = $templateArray[2][$i];
19
		}
20
		return $templateArray;
21
	}
22
23
	public static function getParsedJs(string $name): string {
24
		return self::$parsedJs[$name];
25
	}
26
}
27
28