Completed
Branch 3.0.0 (3f0ab7)
by Serhii
03:15
created

bootstrap.php ➔ testUaListIsProperty()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 4
dl 0
loc 7
rs 9.4285
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 10.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 * @author Sergey Nehaenko <[email protected]>
4
 * @license GPL
5
 * @copyright Sergey Nehaenko &copy 2016
6
 * @version 1.0
7
 * @project browser-detector
8
 */
9
10
$vendor = realpath(__DIR__ . '/../vendor/');
11
12
define('__SRC__',str_replace('tests','src',__DIR__));
13
if (file_exists($vendor . '/autoload.php')) {
14
    require $vendor . '/autoload.php';
15
} else {
16
    $vendor = realpath(__DIR__ . '/../../../');
17
    if (file_exists($vendor . '/autoload.php')) {
18
        require $vendor . '/autoload.php';
19
    } else {
20
        throw new Exception('Unable to load dependencies');
21
    }
22
}
23
24
use Symfony\Component\ClassLoader\Psr4ClassLoader;
25
use EndorphinStudio\Detector\Detector;
26
27
$loader = new Psr4ClassLoader();
28
$loader->addPrefix('EndorphinStudio\\Detector', __SRC__);
29
$loader->register();
30
31
function testUaList($object,$detectorProperty,$property,$uaList,$expectedValue)
32
{
33 View Code Duplication
    foreach($uaList as $ua)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
    {
35
        $obj = Detector::analyse($ua)->$detectorProperty;
36
        $func = 'get'.$property;
37
        $object->assertEquals($expectedValue,$obj->$func());
38
    }
39
}
40
41
function testUaListBooleanTrue($object,$detectorProperty,$property,$uaList)
42
{
43 View Code Duplication
    foreach($uaList as $ua)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
44
    {
45
        $obj = Detector::analyse($ua)->$detectorProperty;
46
        $func = 'is'.$property;
47
        $object->assertTrue($obj->$func(),'Object Property '.$property.' is no equal TRUE');
48
    }
49
}
50
51
function testUaListIsProperty($object,$detectorProperty,$uaList,$expectedValue)
52
{
53
    foreach($uaList as $ua)
54
    {
55
        $object->assertEquals($expectedValue,Detector::analyse($ua)->$detectorProperty);
56
    }
57
}