Completed
Push — master ( dbedfe...a86c06 )
by Diogo Oliveira de
04:51
created

AbstractTable::findOneById()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace SlimX\Models\Tables;
4
5
use Psr\Log\LoggerInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Log\LoggerInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
use RedBeanPHP\OODBBean;
0 ignored issues
show
Bug introduced by
The type RedBeanPHP\OODBBean was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use RedBeanPHP\R;
0 ignored issues
show
Bug introduced by
The type RedBeanPHP\R was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
abstract class AbstractTable
10
{
11
    protected $tableName;
12
    protected $logger;
13
    protected $cache;
14
15
    public function __construct(LoggerInterface $logger)
16
    {
17
        $this->logger = $logger;
18
        $this->cache = [];
19
    }
20
21
    public function findOneById(int $id): ?OODBBean
22
    {
23
        if (!isset($this->cache[$id])) {
24
            $this->logger->debug(get_class($this) . '::findOneById cache miss ' . $id);
25
            $bean = R::findOne($this->tableName, 'id = ? AND active = ?', [$id, 1]);
26
            if (count($this->cache) < 1024) {
27
                $this->cache[$id] = $bean;
28
            }
29
        } else {
30
            $this->logger->debug(get_class($this) . '::findOneById cache hit ' . $id);
31
            $bean = $this->cache[$id];
32
        }
33
34
        return $bean;
35
    }
36
}
37