ComDriver   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 24
c 5
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getFileSize() 0 9 3
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