BigFileTools::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
dl 0
loc 4
c 4
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace BigFileTools;
4
use BigFileTools\Driver\SizeDriverAggregator;
5
use BigFileTools\Driver\ComDriver;
6
use BigFileTools\Driver\CurlDriver;
7
use BigFileTools\Driver\ExecDriver;
8
use BigFileTools\Driver\ISizeDriver;
9
use BigFileTools\Driver\NativeSeekDriver;
10
use BigFileTools\Driver\SizeDriverFactory;
11
12
/**
13
 * @author Honza Kuchař
14
 * @license New BSD
15
 * @encoding UTF-8
16
 * @copyright Copyright (c) 2016, Jan Kuchař
17
 */
18
class BigFileTools {
19
20
	/**
21
	 * Create BigFileTools from $path
22
	 * @param string $path
23
	 * @return File
24
	 * @deprecated
25
	 */
26
	static function fromPath($path) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
27
		return static::createDefault()->getFile($path);
28
	}
29
30
	/**
31
	 * @var SizeDriverAggregator
32
	 */
33
	private $sizeDriver;
34
35
	/**
36
	 * Create new instance of BigFileTools by providing list of drivers.
37
	 * Those that cannot be initialized on given platform will be skipped.
38
	 * @param string[] $drivers
39
	 * @return static
40
	 */
41
	public static function createFrom(array $drivers) {
42
		return new static(
43
			new SizeDriverAggregator(
44
				(new SizeDriverFactory($drivers))->getInitializedDrivers()
45
			)
46
		);
47
	}
48
49
	/**
50
	 * Create new instance of BigFileTools using default configuration.
51
	 * This uses default drivers ordered by speed.
52
	 * @return static
53
	 */
54
	public static function createDefault() {
55
		return static::createFrom([
56
			CurlDriver::class,
57
			NativeSeekDriver::class,
58
			ComDriver::class,
59
			ExecDriver::class,
60
			//NativeReadDriver::class,
61
		]);
62
	}
63
64
	/**
65
	 * Constructor - do not call directly
66
	 * @param ISizeDriver $sizeDriver
67
	 */
68
	function __construct(ISizeDriver $sizeDriver)
69
	{
70
		$this->sizeDriver = $sizeDriver;
0 ignored issues
show
Documentation Bug introduced by
$sizeDriver is of type object<BigFileTools\Driver\ISizeDriver>, but the property $sizeDriver was declared to be of type object<BigFileTools\Driver\SizeDriverAggregator>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
71
	}
72
73
	/**
74
	 * Get file resource for further manipulation
75
	 * @param string $path **full** path to file
76
	 * @return File
77
	 */
78
	public function getFile($path)
79
	{
80
		return new File($path, $this->sizeDriver);
81
	}
82
}
83