Completed
Push — master ( b7cc2d...e2c111 )
by Peter
14:18 queued 10:45
created

RelatedOrderingAnnotation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 66.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 31
ccs 12
cts 18
cp 0.6667
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B init() 0 23 4
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Mangan\Annotations;
10
11
use Maslosoft\Addendum\Helpers\ParamsExpander;
12
use Maslosoft\Mangan\Interfaces\SortInterface;
13
use Maslosoft\Mangan\Meta\ManganPropertyAnnotation;
14
use Maslosoft\Mangan\Meta\RelatedMeta;
15
16
/**
17
 * RelatedOrderingAnnotation
18
 *
19
 * Use this annotation to store order of related documents.
20
 * This should be used on same field as Related or RelatedArray annotations are applied.
21
 * This will apply incrementing values on selected field.
22
 *
23
 * Will also apply sort if not set.
24
 *
25
 * Compact notation:
26
 *
27
 * RelatedOrdering('order')
28
 *
29
 * Extended notation:
30
 *
31
 * RelatedOrdering(orderField = 'order')
32
 *
33
 * @template RelatedOrdering('${orderField}')
34
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
35
 */
36
class RelatedOrderingAnnotation extends ManganPropertyAnnotation
37
{
38
39
	public $value;
40
	public $orderField;
41
42 1
	public function init()
43
	{
44 1
		$data = ParamsExpander::expand($this, ['orderField']);
45 1
		if (empty($this->_entity->related))
46 1
		{
47
			$relMeta = new RelatedMeta();
48
		}
49
		else
50
		{
51 1
			$relMeta = $this->_entity->related;
52
		}
53 1
		foreach ($data as $key => $val)
54
		{
55 1
			$relMeta->$key = $val;
56 1
		}
57 1
		if (empty($relMeta->sort))
58 1
		{
59
			$relMeta->sort = [
1 ignored issue
show
Documentation Bug introduced by
It seems like array($relMeta->orderFie...SortInterface::SortAsc) of type array<string,?> is incompatible with the declared type array<integer,integer> of property $sort.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
60
				$relMeta->orderField => SortInterface::SortAsc
61
			];
62
		}
63 1
		$this->_entity->related = $relMeta;
64 1
	}
65
66
}
67