Passed
Push — master ( 7b14f6...f49505 )
by Gabriel
12:07
created

PropertyRecordTrait::getStatus()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ByTIC\Models\SmartProperties\RecordsTraits\HasStatus;
4
5
use ByTIC\Models\SmartProperties\Properties\AbstractProperty\Generic;
6
7
/**
8
 * Trait PropertyRecordTrait
9
 * @package ByTIC\Models\SmartProperties\RecordsTraits\HasStatus
10
 */
11
trait PropertyRecordTrait
12
{
13
    /**
14
     * @return Generic
15
     */
16
    public function getStatus()
17
    {
18
        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

18
        return $this->/** @scrutinizer ignore-call */ getSmartProperty('Status');
Loading history...
19
    }
20
21
    public function getStatusObject()
22
    {
23
        return $this->getSmartProperty('Status');
24
    }
25
26
    /**
27
     * @param $value
28
     */
29
    public function setStatus($value)
30
    {
31
        /** @noinspection PhpUnhandledExceptionInspection */
32
        $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

32
        $this->/** @scrutinizer ignore-call */ 
33
               setSmartProperty('Status', $value);
Loading history...
33
    }
34
35
    /**
36
     * @param $status
37
     * @return Generic
38
     */
39
    public function getNewStatus($status)
40
    {
41
        /** @noinspection PhpUnhandledExceptionInspection */
42
        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

42
        return $this->/** @scrutinizer ignore-call */ getNewSmartPropertyFromValue('Status', $status);
Loading history...
43
    }
44
45
    /**
46
     * @param bool $status
47
     * @return bool|void
48
     */
49
    public function updateStatus($status = false)
50
    {
51
        /** @noinspection PhpUnhandledExceptionInspection */
52
        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

52
        return $this->/** @scrutinizer ignore-call */ updateSmartProperty('Status', $status);
Loading history...
53
    }
54
55
    public function isInStatus($status): bool
56
    {
57
        $status = is_array($status) ? $status : [$status];
58
        foreach ($status as $singleStatus) {
59
            if ($this->isInStatusSingle($singleStatus)) {
60
                return true;
61
            }
62
        }
63
        return false;
64
    }
65
66
    protected function isInStatusSingle($status): bool
67
    {
68
        $statusObject = $this->getStatusObject();
69
        if (class_exists($status)) {
70
            return ($statusObject instanceof $status);
71
        }
72
73
        return $statusObject->getName() == $status;
74
    }
75
}
76