Character   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 6

Importance

Changes 0
Metric Value
dl 0
loc 49
c 0
b 0
f 0
wmc 2
lcom 0
cbo 6
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFilters() 0 16 1
A findAll() 0 16 1
1
<?php
2
3
namespace Chadicus\Marvel\Api\Entities;
4
5
use Chadicus\Marvel\Api;
6
use DominionEnterprises\Util;
7
8
/**
9
 * Represents a Marvel API Character Entity
10
 *
11
 * @property-read integer $id The unique ID of the character resource.
12
 * @property-read string $name The name of the character.
13
 * @property-read string $description A short bio or description of the character.
14
 * @property-read DateTime $modified The date the resource was most recently modified.
15
 * @property-read string $resourceURI The canonical URL identifier for this resource.
16
 * @property-read Url[] $urls A set of public web site URLs for the resource.
17
 * @property-read Image $thumbnail The representative image for this character.
18
 * @property-read ResourceList $comics A resource list containing comics which feature this character.
19
 * @property-read ResourceList $stories A resource list of stories in which this character appears.
20
 * @property-read ResourceList $events A resource list of events in which this character appears.
21
 * @property-read ResourceList $series A resource list of series in which this character appears.
22
 */
23
class Character extends AbstractEntity
24
{
25
    /**
26
     * @see AbstractEntity::getFilters()
27
     *
28
     * @return array
29
     */
30
    final protected function getFilters() : array
31
    {
32
        return [
33
            'id' => [['int', true]],
34
            'name' => ['default' => '', ['string', true, 0]],
35
            'description' => ['default' => '', ['string', true, 0]],
36
            'modified' => [['date']],
37
            'resourceURI' => ['default' => '', ['string', true, 0]],
38
            'urls' => ['default' => [], ['_urls']],
39
            'thumbnail' => ['default' => new Image(), ['image']],
40
            'comics' => ['default' => new ResourceList(), ['resource-list']],
41
            'stories' => ['default' => new ResourceList(), ['resource-list']],
42
            'events' => ['default' => new ResourceList(), ['resource-list']],
43
            'series' => ['default' => new ResourceList(), ['resource-list']],
44
        ];
45
    }
46
47
    /**
48
     * Find all characters based on the given $criteria.
49
     *
50
     * @param Api\Client $client   The API Client.
51
     * @param array      $criteria The criteria to search with.
52
     *
53
     * @return Api\Collection
54
     */
55
    public static function findAll(Api\Client $client, array $criteria = []) : Api\Collection
56
    {
57
        $filters = [
58
            'name' => [['string']],
59
            'modifiedSince' => [['date', true], ['date-format', 'c']],
60
            'comics' => [['ofScalars', [['uint']]], ['implode', ',']],
61
            'series' => [['ofScalars', [['uint']]], ['implode', ',']],
62
            'events' => [['ofScalars', [['uint']]], ['implode', ',']],
63
            'stories' => [['ofScalars', [['uint']]], ['implode', ',']],
64
            'orderBy' => [['in', ['name', 'modified', '-name', '-modified']]],
65
        ];
66
        list($success, $filteredCriteria, $error) = Api\Filterer::filter($filters, $criteria);
67
        Util::ensure(true, $success, $error);
68
69
        return new Api\Collection($client, 'characters', $filteredCriteria);
70
    }
71
}
72