Applier   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 57
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 3
A apply() 0 10 2
A _apply() 0 8 2
1
<?php
2
3
/**
4
 * This software package is licensed under `AGPL, Commercial` license[s].
5
 *
6
 * @package maslosoft/zamm
7
 * @license AGPL, Commercial
8
 *
9
 * @copyright Copyright (c) Peter Maselkowski <[email protected]>
10
 * @link https://maslosoft.com/zamm/
11
 */
12
13
namespace Maslosoft\Zamm\File;
14
15
use Maslosoft\Zamm\Interfaces\ConverterInterface;
16
use SplFileInfo;
17
use Symfony\Component\Finder\Finder;
18
use Symfony\Component\Finder\SplFileInfo as SfFileInfo;
19
20
/**
21
 * Applier
22
 *
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
class Applier
26
{
27
28
	/**
29
	 * Array of directories
30
	 * @var string[]
31
	 */
32
	private $_dirs = [];
33
34
	/**
35
	 * Array of files
36
	 * @var string
37
	 */
38
	private $_files = [];
39
40
	/**
41
	 * Output folder
42
	 * @var string
43
	 */
44
	private $_output = '';
45
46
	public function __construct(array $input, $output)
47
	{
48
		$this->_output = $output;
49
		foreach ($input as $entry)
50
		{
51
			$info = new SplFileInfo($entry);
52
			if ($info->isFile())
53
			{
54
				$this->_files[] = $info->getPathname();
55
				continue;
56
			}
57
			$this->_dirs[] = $info->getPathname();
58
		}
59
	}
60
61
	public function apply(array $converters)
62
	{
63
		$finder = new Finder();
64
65
		foreach ($finder->files()->name('*.php')->ignoreVCS(true)->in($this->_dirs) as $info)
66
		{
67
			/* @var $info SfFileInfo */
68
			$this->_apply($info->get, $converters);
0 ignored issues
show
Bug introduced by
The property get does not seem to exist in Symfony\Component\Finder\SplFileInfo.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
69
		}
70
	}
71
72
	private function _apply($src, array $converters)
73
	{
74
		foreach ($converters as $converter)
75
		{
76
			/* @var $converter ConverterInterface */
77
			$converter->input($src)->output($this->_output);
0 ignored issues
show
Bug introduced by
The call to input() misses a required argument $fileName.

This check looks for function calls that miss required arguments.

Loading history...
Documentation introduced by
$this->_output is of type string, but the function expects a object<Maslosoft\Zamm\Interfaces\OutputInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
78
		}
79
	}
80
81
}
82