Resource   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 1
dl 0
loc 88
c 0
b 0
f 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A guessClassFromTypes() 0 13 5
1
<?php declare(strict_types = 1);
2
3
namespace JSKOS;
4
5
/**
6
 * JSKOS Specification version aligned with.
7
 */
8
const JSKOS_SPECIFICATION = '0.4.5';
9
10
use InvalidArgumentException;
11
12
/**
13
 * A JSKOS resource with support of common fields.
14
 *
15
 * @see https://gbv.github.io/jskos/jskos.html#jskos-resources
16
 */
17
abstract class Resource extends DataType
18
{
19
    const CLASSES = ['ConceptScheme', 'Concordance', 'Mapping', 'Registry', 'Concept'];
20
21
    const TYPES = [];
22
23
    const FIELDS = [
24
        'uri'         => 'URI',
25
        'type'        => ['Listing'],
26
        'identifier'  => ['Listing'],
27
        'created'     => 'Date',
28
        'issued'      => 'Date',
29
        'modified'    => 'Date',
30
        'creator'     => ['Set', 'Concept'],
31
        'contributor' => ['Set', 'Concept'],
32
        'publisher'   => ['Set', 'Concept'],
33
        'partOf'      => ['Set', 'Concept'],
34
    ];
35
36
    /**
37
     * URI if the Concept, ConceptScheme, ConceptType, Mapping
38
     * or whatever this resource refers to.
39
     */
40
    protected $uri;
41
42
    /**
43
     * Additional identifiers.
44
     */
45
    protected $identifier;
46
    
47
    /**
48
     * Resource types(s).
49
     */
50
    protected $type;
51
52
    /**
53
     * Date of creation.
54
     */
55
    protected $created;
56
57
    /**
58
     * Date of protectedation.
59
     */
60
    protected $issued;
61
62
    /**
63
     * Date of last modification.
64
     */
65
    protected $modified;
66
67
    /**
68
     * Agent primarily responsible for creation of resource.
69
     */
70
    protected $creator;
71
72
    /**
73
     * Agent responsible for making contributions to the resource.
74
     */
75
    protected $contributor;
76
77
    /**
78
     * Agent responsible for making the resource available.
79
     */
80
    protected $publisher;
81
82
    /**
83
     * Resources which this resource is part of.
84
     */
85
    protected $partOf;
86
87
88
    /**
89
     * Guess subclass from list of type URIs.
90
     */
91
    public static function guessClassFromTypes(array $types)
92
    {
93
        if (count($types)) {
94
            foreach (Resource::CLASSES as $class) {
95
                $class = "JSKOS\\$class";
96
                foreach ($class::TYPES as $uri) {
97
                    if (in_array($uri, $types)) {
98
                        return $class;
99
                    }
100
                }
101
            }
102
        }
103
    }
104
}
105