These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace smtech\GradingAnalytics\Snapshots; |
||
4 | |||
5 | use mysqli; |
||
6 | use smtech\ReflexiveCanvasLTI\Toolbox; |
||
7 | use smtech\GradingAnalytics\Snapshots\Exception\SnapshotException; |
||
8 | use Battis\HierarchicalSimpleCache; |
||
9 | |||
10 | class CacheableDatabase |
||
11 | { |
||
12 | /** |
||
13 | * MySQL database access |
||
14 | * @var mysqli |
||
15 | */ |
||
16 | protected $sql; |
||
17 | |||
18 | /** |
||
19 | * Caching for queried data |
||
20 | * @var HierarchicalSimpleCache |
||
21 | */ |
||
22 | protected $cache; |
||
23 | |||
24 | public function __construct($databaseProvider) |
||
25 | { |
||
26 | $this->sql = false; |
||
27 | if (is_a($databaseProvider, mysqli::class)) { |
||
28 | $this->sql = $databaseProvider; |
||
29 | } elseif (is_a($databaseProvider, CacheableDatabase::class)) { |
||
30 | $this->sql = $databaseProvider->sql; |
||
31 | } elseif (is_a($databaseProvider, Toolbox::class)) { |
||
32 | $this->sql = $databaseProvider->getMySql(); |
||
33 | } |
||
34 | |||
35 | if (!is_a($this->sql, mysqli::class)) { |
||
36 | throw new SnapshotException( |
||
37 | 'Database provider not recognized (instance of ' . (is_object($databaseProvider) ? |
||
38 | get_class($databaseProvider) : |
||
39 | gettype($databaseProvider) |
||
40 | ) .')', |
||
41 | SnapshotException::MYSQL |
||
42 | ); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | protected function getMySql() |
||
47 | { |
||
48 | return $this->sql; |
||
49 | } |
||
50 | |||
51 | protected function getCache() |
||
52 | { |
||
53 | if (empty($this->cache)) { |
||
54 | $this->cache = new HierarchicalSimpleCache( |
||
55 | $this->getMySql(), |
||
56 | get_class($this), |
||
57 | true |
||
0 ignored issues
–
show
|
|||
58 | ); |
||
59 | } |
||
60 | return $this->cache; |
||
61 | } |
||
62 | } |
||
63 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.