Completed
Push — master ( 5decb7...aee104 )
by Thibaud
14:37 queued 11:26
created

Record   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 92.86%

Importance

Changes 8
Bugs 0 Features 0
Metric Value
wmc 7
c 8
b 0
f 0
lcom 1
cbo 6
dl 0
loc 74
ccs 26
cts 28
cp 0.9286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findById() 0 17 3
A find() 0 16 2
A search() 0 13 2
1
<?php
2
3
/*
4
 * This file is part of Phraseanet SDK.
5
 *
6
 * (c) Alchemy <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace PhraseanetSDK\Repository;
13
14
use PhraseanetSDK\AbstractRepository;
15
use PhraseanetSDK\Entity\Query;
16
use PhraseanetSDK\Exception\RuntimeException;
17
use Doctrine\Common\Collections\ArrayCollection;
18
19
class Record extends AbstractRepository
20
{
21
    /**
22
     * Find the record by its id that belongs to the provided databox
23
     *
24
     * @param  integer                      $databoxId The record databox id
25
     * @param  integer                      $recordId  The record id
26
     * @return \PhraseanetSDK\Entity\Record
27
     * @throws RuntimeException
28
     */
29 2
    public function findById($databoxId, $recordId, $disableCache = false)
30
    {
31 2
        $path = sprintf('v1/records/%s/%s/', $databoxId, $recordId);
32 2
        $query = [];
33
34 2
        if ($disableCache) {
35
            $query['t'] = time();
36
        }
37
38 2
        $response = $this->query('GET', $path, $query);
39
40 2
        if (true !== $response->hasProperty('record')) {
41 1
            throw new RuntimeException('Missing "record" property in response content');
42
        }
43
44 1
        return \PhraseanetSDK\Entity\Record::fromValue($response->getProperty('record'));
0 ignored issues
show
Bug introduced by
It seems like $response->getProperty('record') targeting PhraseanetSDK\Http\APIResponse::getProperty() can also be of type array<integer,object<stdClass>> or null; however, PhraseanetSDK\Entity\Record::fromValue() does only seem to accept object<stdClass>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
45
    }
46
47
    /**
48
     * Find records
49
     *
50
     * @param  integer          $offsetStart The offset
51
     * @param  integer          $perPage     The number of item per page
52
     * @return ArrayCollection
53
     * @throws RuntimeException
54
     */
55 2
    public function find($offsetStart, $perPage)
56
    {
57 2
        $response = $this->query('POST', 'v1/records/search/', array(), array(
58 2
            'query'        => 'all',
59 2
            'offset_start' => (int) $offsetStart,
60 2
            'per_page'     => (int) $perPage,
61 2
        ));
62
63 2
        if (true !== $response->hasProperty('results')) {
64 1
            throw new RuntimeException('Missing "results" property in response content');
65
        }
66
67 1
        return new ArrayCollection(\PhraseanetSDK\Entity\Record::fromList(
68 1
            $response->getProperty('results')
0 ignored issues
show
Bug introduced by
It seems like $response->getProperty('results') targeting PhraseanetSDK\Http\APIResponse::getProperty() can also be of type null or object<stdClass>; however, PhraseanetSDK\Entity\Record::fromList() does only seem to accept array<integer,object<stdClass>>, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
69 1
        ));
70
    }
71
72
    /**
73
     * Search for records
74
     *
75
     * @param  array                       $parameters Query parameters
76
     * @return \PhraseanetSDK\Entity\Query object
77
     * @throws RuntimeException
78
     */
79 2
    public function search(array $parameters = array())
80
    {
81 2
        $response = $this->query('POST', 'v1/search/', array(), array_merge(
82 2
            array('search_type' => 0),
83
            $parameters
84 2
        ));
85
86 2
        if ($response->isEmpty()) {
87 1
            throw new RuntimeException('Response content is empty');
88
        }
89
90 1
        return Query::fromValue($this->em, $response->getResult());
91
    }
92
}
93