Test Failed
Pull Request — main (#64)
by Lode
08:15
created

MetaDocument::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 3
1
<?php
2
3
namespace alsvanzelf\jsonapi;
4
5
use alsvanzelf\jsonapi\Document;
6
use alsvanzelf\jsonapi\helpers\Converter;
7
use alsvanzelf\jsonapi\objects\MetaObject;
8
9
/**
10
 * this document can be used if neither data nor errors need to be set
11
 * meta can also be added to ResourceDocument, CollectionDocument and ErrorsDocument via `addMeta()`
12
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @category tag in class comment
Loading history...
13
class MetaDocument extends Document {
14
	/**
15
	 * human api
16
	 */
17
	
18
	/**
19
	 * @param  array $meta
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
20
	 * @return MetaDocument
21
	 */
22
	public static function fromArray(array $meta) {
23
		$metaDocument = new self();
24
		$metaDocument->setMetaObject(MetaObject::fromArray($meta));
25
		
26
		return $metaDocument;
27
	}
28
	
29
	/**
30
	 * @param  object $meta
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
31
	 * @return MetaDocument
32
	 */
33
	public static function fromObject($meta) {
34
		$array = Converter::objectToArray($meta);
35
		
36
		return self::fromArray($array);
37
	}
38
	
39
	/**
40
	 * wrapper for Document::addMeta() to the primary data of this document available via `add()`
41
	 * 
42
	 * @param string $key
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
43
	 * @param mixed  $value
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
44
	 * @param string $level one of the Document::LEVEL_* constants, optional, defaults to Document::LEVEL_ROOT
45
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
46
	public function add($key, $value, $level=Document::LEVEL_ROOT) {
47
		parent::addMeta($key, $value, $level);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (addMeta() instead of add()). Are you sure this is correct? If so, you might want to change this to $this->addMeta().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
48
	}
49
	
50
	/**
51
	 * spec api
52
	 */
53
	
54
	/**
55
	 * DocumentInterface
56
	 */
57
	
58
	/**
59
	 * @inheritDoc
60
	 */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
61
	public function toArray() {
62
		$array = parent::toArray();
63
		
64
		// force meta to be set, and be an object when converting to json
65
		if (isset($array['meta']) === false) {
66
			$array['meta'] = new \stdClass();
67
		}
68
		
69
		return $array;
70
	}
71
}
72