SystemWarnings::getFolders()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 22
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 5.0144

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 22
rs 9.4222
c 0
b 0
f 0
ccs 11
cts 12
cp 0.9167
cc 5
nc 6
nop 0
crap 5.0144
1
<?php
2
/**
3
 * System warnings basic file.
4
 *
5
 * @package App
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license   YetiForce Public License 6.5 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Mariusz Krzaczkowski <[email protected]>
10
 * @author    Radosław Skrzypczak <[email protected]>
11
 */
12
13
namespace App;
14
15
/**
16
 * System warnings basic class.
17
 */
18
class SystemWarnings
19
{
20
	const FOLDERS = 'app/SystemWarnings';
21
	const SELECTED_FOLDERS = ['SystemRequirements', 'YetiForce', 'Security', 'Mail'];
22 1
23
	/**
24 1
	 * Returns a list of folders warnings.
25 1
	 *
26 1
	 * @return array
27 1
	 */
28 1
	public static function getFolders()
29 1
	{
30 1
		$folders = [];
31 1
		$i = 0;
32 1
		foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
33 1
			if ($item->isDir()) {
34
				$subPath = $iterator->getSubPathName();
0 ignored issues
show
Bug introduced by
The method getSubPathName() does not exist on RecursiveIteratorIterator. ( Ignorable by Annotation )

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

34
				/** @scrutinizer ignore-call */ 
35
    $subPath = $iterator->getSubPathName();

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...
35
				$fileName = $item->getFilename();
36 1
				$subPath = str_replace(\DIRECTORY_SEPARATOR, '/', $subPath);
37 1
				$parent = rtrim(rtrim($subPath, $fileName), '/');
38
				$folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
39 1
				if (isset($folders[$parent])) {
40
					$folder['parent'] = $folders[$parent]['id'];
41 1
				}
42
				if (\in_array($subPath, self::SELECTED_FOLDERS)) {
43 1
					$folder['state']['selected'] = true;
44
				}
45
				$folders[$subPath] = $folder;
46
			}
47
			++$i;
48
		}
49
		return $folders;
50
	}
51
52
	/**
53
	 * Returns a list of warnings instance.
54 1
	 *
55
	 * @param array $folders
56 1
	 * @param mixed $active
57
	 *
58
	 * @return array
59 1
	 */
60 1
	public static function getWarnings($folders, $active = true)
61
	{
62 1
		if (empty($folders)) {
63 1
			return [];
64 1
		}
65 1
		if (!\is_array($folders) && 'all' === $folders) {
0 ignored issues
show
introduced by
The condition is_array($folders) is always true.
Loading history...
66
			$folders = array_keys(static::getFolders());
67
		}
68 1
		$actions = [];
69 1
		foreach ($folders as $folder) {
70 1
			$dir = self::FOLDERS . '/' . $folder;
71 1
			if (!is_dir($dir)) {
72 1
				continue;
73 1
			}
74 1
			$iterator = new \DirectoryIterator($dir);
75 1
			foreach ($iterator as $item) {
76 1
				if (!$item->isDot() && !$item->isDir()) {
77 1
					$fileName = $item->getBasename('.php');
78 1
					$folder = str_replace('/', '\\', $folder);
79 1
					$className = "\\App\\SystemWarnings\\$folder\\$fileName";
80
					$instace = new $className();
81 1
					if ($instace->preProcess()) {
82 1
						$isIgnored = 2 === $instace->getStatusValue();
83
						if (!$active || !$isIgnored) {
84 1
							$instace->process();
85 1
						}
86 1
						if (!$active || (!$isIgnored && 1 !== $instace->getStatus())) {
87
							$instace->setFolder($folder);
88
							$actions[$instace->getPriority() . $fileName] = $instace;
89
						}
90
					}
91
				}
92 1
			}
93
		}
94 1
		krsort($actions);
95
96
		return $actions;
97
	}
98
}
99