PropertyRecordTrait   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 12
eloc 20
c 3
b 1
f 1
dl 0
loc 80
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A isInStatusSingle() 0 8 2
A getStatusObject() 0 9 2
A setStatus() 0 4 1
A isInStatus() 0 9 4
A getNewStatus() 0 4 1
A getStatus() 0 3 1
A updateStatus() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace ByTIC\Models\SmartProperties\RecordsTraits\HasStatus;
5
6
use ByTIC\Models\SmartProperties\Properties\AbstractProperty\Generic;
7
8
/**
9
 * Trait PropertyRecordTrait
10
 * @package ByTIC\Models\SmartProperties\RecordsTraits\HasStatus
11
 */
12
trait PropertyRecordTrait
13
{
14
    /**
15
     * @return Generic
16
     */
17
    public function getStatus()
18
    {
19
        return $this->getSmartProperty('Status');
0 ignored issues
show
Bug introduced by
It seems like getSmartProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

19
        return $this->/** @scrutinizer ignore-call */ getSmartProperty('Status');
Loading history...
20
    }
21
22
    /**
23
     * @return Generic|null
24
     */
25
    public function getStatusObject()
26
    {
27
        $status = $this->getPropertyRaw('status');
0 ignored issues
show
Bug introduced by
It seems like getPropertyRaw() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        /** @scrutinizer ignore-call */ 
28
        $status = $this->getPropertyRaw('status');
Loading history...
28
        $property = $this->getSmartProperty('Status');
29
        if ($status == $property->getName()) {
30
            return $property;
31
        }
32
        $this->setStatus($status);
33
        return $this->getSmartProperty('Status');
34
    }
35
36
    /**
37
     * @param $value
38
     */
39
    public function setStatus($value)
40
    {
41
        /** @noinspection PhpUnhandledExceptionInspection */
42
        $this->setSmartProperty('Status', $value);
0 ignored issues
show
Bug introduced by
It seems like setSmartProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

42
        $this->/** @scrutinizer ignore-call */ 
43
               setSmartProperty('Status', $value);
Loading history...
43
    }
44
45
    /**
46
     * @param $status
47
     * @return Generic
48
     */
49
    public function getNewStatus($status)
50
    {
51
        /** @noinspection PhpUnhandledExceptionInspection */
52
        return $this->getNewSmartPropertyFromValue('Status', $status);
0 ignored issues
show
Bug introduced by
It seems like getNewSmartPropertyFromValue() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
        return $this->/** @scrutinizer ignore-call */ getNewSmartPropertyFromValue('Status', $status);
Loading history...
53
    }
54
55
    /**
56
     * @param bool $status
57
     * @return bool|void
58
     */
59
    public function updateStatus($status = false)
60
    {
61
        /** @noinspection PhpUnhandledExceptionInspection */
62
        return $this->updateSmartProperty('Status', $status);
0 ignored issues
show
Bug introduced by
It seems like updateSmartProperty() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

62
        return $this->/** @scrutinizer ignore-call */ updateSmartProperty('Status', $status);
Loading history...
63
    }
64
65
    /**
66
     * @param $status
67
     * @return bool
68
     */
69
    public function isInStatus($status): bool
70
    {
71
        $status = is_array($status) ? $status : [$status];
72
        foreach ($status as $singleStatus) {
73
            if ($this->isInStatusSingle($singleStatus)) {
74
                return true;
75
            }
76
        }
77
        return false;
78
    }
79
80
    /**
81
     * @param $status
82
     * @return bool
83
     */
84
    protected function isInStatusSingle($status): bool
85
    {
86
        $statusObject = $this->getStatusObject();
87
        if (class_exists($status)) {
88
            return ($statusObject instanceof $status);
89
        }
90
91
        return $statusObject->getName() == $status;
92
    }
93
}
94