Completed
Push — master ( 36b546...cd40ca )
by Henri
07:20
created

VocabularyCategory::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %
Metric Value
dl 10
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
1
<?php
2
/**
3
 * Copyright (c) 2012-2013 Aalto University and University of Helsinki
4
 * MIT License
5
 * see LICENSE.txt for more information
6
 */
7
8
/**
9
 * Groups vocabularies of a specific category into a DataObject.
10
 */
11
class VocabularyCategory extends DataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
12
{
13 View Code Duplication
    public function __construct($model, $resource)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
14
    {
15
        if (!($model instanceof Model)) {
16
            throw new Exception('Invalid constructor parameter given to DataObject.');
17
        }
18
19
        $this->model = $model;
20
        $this->resource = $resource;
21
        $this->order = array();
22
    }
23
24
    /**
25
     * Returns all vocabularies in the category.
26
     */
27
    public function getVocabularies()
28
    {
29
        if ($this->resource) {
30
            return $this->model->getVocabulariesInCategory($this->resource);
31
        }
32
        return $this->model->getVocabularies();
33
    }
34
35
    /**
36
     * Returns the title of the category.
37
     */
38
    public function getTitle()
39
    {
40
        if ($this->resource) {
41
            $label = $this->resource->label($this->getEnvLang());
42
            return is_null($label) ? $this->resource->localName() : $label->getValue();
1 ignored issue
show
Bug introduced by
The method getValue cannot be called on $label (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
43
        }
44
        return gettext('vocabularies');
45
    }
46
47
}
48