Completed
Pull Request — development (#807)
by
unknown
05:10
created

CacheService::fetchOneByName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Oc\Cache;
4
5
use Doctrine\DBAL\Connection;
6
use Oc\Entity\CacheEntity;
7
use Oc\Repository\Exception\RecordNotFoundException;
8
use Oc\Repository\Exception\RecordsNotFoundException;
9
use Oc\Repository\CacheRepository;
10
11
class CacheService
12
{
13
    /**
14
     * @var CacheRepository
15
     */
16
    private $cacheRepository;
17
18
//    public function __construct(CacheRepository $cacheRepository)
19
    public function __construct(Connection $connection, SecurityRolesRepository  $securityRolesRepository) //test
0 ignored issues
show
Unused Code introduced by
The parameter $connection 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...
Unused Code introduced by
The parameter $securityRolesRepository 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...
20
    {
21
//        $this->cacheRepository = $cacheRepository;
22
23
//        $this->connection = $connection;
24
//        $this->securityRolesRepository = $securityRolesRepository;
25
    }
26
27
    /**
28
     * Fetches all caches.
29
     *
30
     * @return CacheEntity[]
31
     */
32
    public function fetchAll(): array
33
    {
34
        try {
35
            $result = $this->cacheRepository->fetchAll();
36
        } catch (RecordsNotFoundException $e) {
37
            $result = [];
38
        }
39
40
        return $result;
41
    }
42
43
    /**
44
     * Fetches a cache by its id.
45
     */
46
    public function fetchOneById(int $cache_id): ?CacheEntity
0 ignored issues
show
Unused Code introduced by
The parameter $cache_id 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...
47
    {
48
        try {
49
            $result = $this->cacheRepository->fetchOneById($id);
0 ignored issues
show
Bug introduced by
The variable $id does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
50
        } catch (RecordNotFoundException $e) {
51
            $result = null;
52
        }
53
54
        return $result;
55
    }
56
57
    /**
58
     * Fetches a cache by its wp_oc.
59
     */
60
    public function fetchOneByWpOC(text $cache_wp_oc): ?CacheEntity
0 ignored issues
show
Unused Code introduced by
The parameter $cache_wp_oc 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...
61
    {
62
        try {
63
            $result = $this->cacheRepository->fetchOneById($wp_oc);
0 ignored issues
show
Bug introduced by
The variable $wp_oc does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
64
        } catch (RecordNotFoundException $e) {
65
            $result = null;
66
        }
67
68
        return $result;
69
    }
70
71
    /**
72
     * Fetches a cache by its name.
73
     */
74
    public function fetchOneByName(text $cache_name): ?CacheEntity
0 ignored issues
show
Unused Code introduced by
The parameter $cache_name 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...
75
    {
76
        try {
77
            $result = $this->cacheRepository->fetchOneById($name);
0 ignored issues
show
Bug introduced by
The variable $name does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
78
        } catch (RecordNotFoundException $e) {
79
            $result = null;
80
        }
81
82
        return $result;
83
    }
84
85
}
86