CachedRelationship   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 5
Bugs 3 Features 0
Metric Value
wmc 5
c 5
b 3
f 0
lcom 1
cbo 0
dl 0
loc 67
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPivotAttributes() 0 4 1
A getHash() 0 4 1
A getPivotAttributes() 0 4 1
A __toString() 0 4 1
A __construct() 0 5 1
1
<?php
2
3
namespace Analogue\ORM\System;
4
5
/**
6
 * This class is intended to facilitate the handling of ManyToMany relationships
7
 * inside the cache
8
 */
9
class CachedRelationship
10
{
11
    /**
12
     * The Hash of the related entity
13
     *
14
     * @var string
15
     */
16
    protected $hash;
17
18
    /**
19
     * Pivot attributes, if any
20
     *
21
     * @var array
22
     */
23
    protected $pivotAttributes;
24
25
    /**
26
     * CachedRelationship constructor.
27
     * @param $hash
28
     * @param array $pivotAttributes
29
     */
30
    public function __construct($hash, $pivotAttributes = [])
31
    {
32
        $this->hash = $hash;
33
        $this->pivotAttributes = $pivotAttributes;
34
    }
35
36
    /**
37
     * Return true if any pivot attributes are present
38
     *
39
     * @return boolean
40
     */
41
    public function hasPivotAttributes()
42
    {
43
        return count($this->pivotAttributes) > 0;
44
    }
45
46
    /**
47
     * Returns the hash of the related entity
48
     *
49
     * @return string
50
     */
51
    public function getHash()
52
    {
53
        return $this->hash;
54
    }
55
56
    /**
57
     * Get the cached values for the pivot attributes
58
     *
59
     * @return array
60
     */
61
    public function getPivotAttributes()
62
    {
63
        return $this->pivotAttributes;
64
    }
65
66
    /**
67
     * Access to the hash for fast cache comparison
68
     *
69
     * @return string
70
     */
71
    public function __toString()
72
    {
73
        return $this->hash;
74
    }
75
}
76