TimedExecutor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 20
c 1
b 0
f 0
dl 0
loc 54
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A resultSetToArray() 0 3 1
A getTimingData() 0 3 1
A getExecuteFileCallable() 0 9 1
A getExecuteCommandCallable() 0 9 1
A __construct() 0 3 1
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace Db3v4l\Core\SqlExecutor\InProcess;
4
5
use Db3v4l\API\Interfaces\SqlExecutor\InProcess\CommandExecutor;
6
use Db3v4l\API\Interfaces\SqlExecutor\InProcess\FileExecutor;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Db3v4l\Core\SqlExecutor\InProcess\FileExecutor. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
7
use Db3v4l\API\Interfaces\TimedExecutor as TimedExecutorInterface;
8
9
class TimedExecutor implements TimedExecutorInterface, CommandExecutor, FileExecutor
0 ignored issues
show
Coding Style introduced by
Missing doc comment for class TimedExecutor
Loading history...
10
{
11
    /** @var CommandExecutor|FileExecutor $wrappedExecutor */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
12
    protected $wrappedExecutor;
13
    protected $timingData = [];
14
15
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
16
     * @param CommandExecutor|FileExecutor $wrappedExecutor
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
17
     */
18
    public function __construct($wrappedExecutor)
19
    {
20
        $this->wrappedExecutor = $wrappedExecutor;
21
    }
22
23
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
24
     * @param string $sql
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
25
     * @return Callable
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
26
     */
27
    public function getExecuteCommandCallable($sql)
28
    {
29
        $callable = $this->wrappedExecutor->getExecuteCommandCallable($sql);
0 ignored issues
show
Bug introduced by
The method getExecuteCommandCallable() does not exist on Db3v4l\API\Interfaces\Sq...\InProcess\FileExecutor. It seems like you code against a sub-type of said class. However, the method does not exist in Db3v4l\Core\SqlExecutor\InProcess\FileExecutor. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

29
        /** @scrutinizer ignore-call */ 
30
        $callable = $this->wrappedExecutor->getExecuteCommandCallable($sql);
Loading history...
30
        return function() use ($callable) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
31
            $time = microtime(true);
32
            $results = call_user_func($callable);
33
            $time = microtime(true) - $time;
34
            $this->timingData = ['memory' => null, 'time' => sprintf('%.3d', $time)];
35
            return $results;
36
        };
37
    }
38
39
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
40
     * @param string $filename
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
41
     * @return Callable
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
42
     */
43
    public function getExecuteFileCallable($filename)
44
    {
45
        $callable = $this->wrappedExecutor->getExecuteFileCallable($filename);
0 ignored issues
show
Bug introduced by
The method getExecuteFileCallable() does not exist on Db3v4l\API\Interfaces\Sq...Process\CommandExecutor. It seems like you code against a sub-type of Db3v4l\API\Interfaces\Sq...Process\CommandExecutor such as Db3v4l\Core\SqlExecutor\InProcess\TimedExecutor or Db3v4l\Core\SqlExecutor\InProcess\Queued. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

45
        /** @scrutinizer ignore-call */ 
46
        $callable = $this->wrappedExecutor->getExecuteFileCallable($filename);
Loading history...
46
        return function() use ($callable) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
47
            $time = microtime(true);
48
            $results = call_user_func($callable);
49
            $time = microtime(true) - $time;
50
            $this->timingData = ['memory' => null, 'time' => sprintf('%.3d', $time)];
51
            return $results;
52
        };
53
    }
54
55
    public function resultSetToArray($data)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function resultSetToArray()
Loading history...
56
    {
57
        return $this->wrappedExecutor->resultSetToArray($data);
58
    }
59
60
    public function getTimingData($onceIsEnough = true)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getTimingData()
Loading history...
61
    {
62
        return $this->timingData;
63
    }
64
}
65