Passed
Push — master ( 8d7c1d...403b82 )
by Richard
09:13 queued 07:02
created

benchmark.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/******************************************************************************
3
 * An iterator interface over the Leagues flysystem.
4
 * Copyright (c) 2021, 2015 Richard Klees <[email protected]>
5
 *
6
 * This software is licensed under GPLv3. You should have received
7
 * a copy of the along with the code.
8
 */
9
10
require_once("tests/autoloader.php");
11
12
$adapter = new \League\Flysystem\Adapter\Local(__DIR__);
13
$flysystem = new \League\Flysystem\Filesystem($adapter);
14
$flightcontrol_strict = new \Lechimp\Flightcontrol\Flightcontrol($flysystem);
15
16
$dir = $flightcontrol_strict->directory("");
17
18
$runs = 100;
19
$count = 0;
20
21
$start = microtime(true);
22
for($i = 0; $i < $runs; $i++) {
23
    $count = 0;
24
    $dir
0 ignored issues
show
The method iterateOn does only exist in Lechimp\Flightcontrol\Directory, but not in Lechimp\Flightcontrol\File.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
25
        ->iterateOn()
26
            ->iterateOn()
27
            ->with(function($obj) use (&$count) {
0 ignored issues
show
The parameter $obj is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
28
                $count += 1;  
29
            });
30
}
31
$end = microtime(true);
32
$diff = $end - $start;
33
34
echo "Flightcontrol: ".sprintf("%10.4f", $diff)." s (and counted $count)\n";
35
36
$start = microtime(true);
37
for ($i = 0; $i < $runs; $i++) {
38
    $count = 0;
39
    foreach($flysystem->listContents() as $dir) {
40
        foreach($flysystem->listContents($dir["path"]) as $dir2) {
41
            $count += 1;
42
        }
43
    }
44
}
45
$end = microtime(true);
46
$diff = $end - $start;
47
48
echo "Flysystem:     ".sprintf("%10.4f", $diff)." s (and counted $count)\n";
49
50
$start = microtime(true);
51
for ($i = 0; $i < $runs; $i++) {
52
    $count = 0;
53
    foreach(scandir(".") as $dir) {
54
        if (!is_dir($dir) or $dir == "." or $dir == "..") {
55
            continue;
56
        }
57
        foreach(scandir("./$dir") as $dir2) {
58
            if ($dir2 == "." or $dir2 == "..") {
59
                continue;
60
            }
61
            $count += 1;
62
        }
63
    }
64
}
65
$end = microtime(true);
66
$diff = $end - $start;
67
68
echo "scandir:       ".sprintf("%10.4f", $diff)." s (and counted $count)\n";
69
70
71