ComDriver::getFileSize()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 9
c 2
b 0
f 0
rs 9.6666
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace BigFileTools\Driver;
4
5
use Brick\Math\BigInteger;
6
7
class ComDriver implements ISizeDriver
8
{
9
	public function __construct()
10
	{
11
		if (!class_exists("COM")) {
12
			throw new PrerequisiteException("ComDriver requires COM extension to be loaded in PHP");
13
		}
14
	}
15
16
	/**
17
	 * Returns file size by using Windows COM interface
18
	 * @inheritdoc
19
	 * @link http://stackoverflow.com/questions/5501451/php-x86-how-to-get-filesize-of-2gb-file-without-external-program/5502328#5502328
20
	 */
21
	public function getFileSize($path)
22
	{
23
		// Use the Windows COM interface
24
		$fsobj = new \COM('Scripting.FileSystemObject');
25
		if (dirname($path) == '.')
26
			$this->path = ((substr(getcwd(), -1) == DIRECTORY_SEPARATOR) ? getcwd() . basename($path) : getcwd() . DIRECTORY_SEPARATOR . basename($path));
0 ignored issues
show
Bug introduced by
The property path does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
		$f = $fsobj->GetFile($path);
28
		return BigInteger::of($f->Size);
29
	}
30
}
31