Passed
Push — master ( 51be4e...ecae65 )
by Vítězslav
04:27
created

Molecule::__sleep()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 0
dl 0
loc 13
ccs 0
cts 10
cp 0
crap 12
rs 9.9666
c 0
b 0
f 0
1
<?php
2
/**
3
 * Something between Atom and Sand
4
 *
5
 * @author    Vitex <[email protected]>
6
 * @copyright 2009-2019 [email protected] (G)
7
 */
8
9
namespace Ease;
10
11
/**
12
 * Description of Molecule
13
 *
14
 * @author vitex
15
 */
16
class Molecule extends Atom
17
{
18
19
    /**
20
     * Here Live Shared Object
21
     * 
22
     * @var Shared 
23
     */
24
    public $easeShared = null;
25
    
26
    /**
27
     *
28
     * @var Logger\Regent 
29
     */
30
    private $logger;
31
32
    /**
33
     * Molecule Can Log and Use Shared
34
     */
35 1
    public function __construct()
36
    {
37 1
        $this->easeShared = Shared::singleton();
38 1
        $this->logger     = $this->easeShared->logger();
39
40 1
        $this->setObjectName();
41 1
    }
42
43
    /**
44
     * Nastaví jméno objektu.
45
     *
46
     * @param string $objectName
47
     *
48
     * @return string Jméno objektu
49
     */
50 1
    public function setObjectName($objectName = null)
51
    {
52 1
        if (empty($objectName)) {
53 1
            $this->objectName = get_class($this);
54
        } else {
55
            $this->objectName = $objectName;
56
        }
57
58 1
        return $this->objectName;
59
    }
60
61
    /**
62
     * Vrací jméno objektu.
63
     *
64
     * @return string
65
     */
66
    public function getObjectName()
67
    {
68
        return $this->objectName;
69
    }
70
71
    /**
72
     * Set up one of properties
73
     *
74
     * @param array  $options  array of given properties
75
     * @param string $name     name of property to process
76
     * @param string $constant load default property value from constant
77
     */
78
    public function setupProperty($options, $name, $constant = null)
79
    {
80
        if (isset($options[$name])) {
81
            $this->$name = $options[$name];
82
        } else {
83
            if (is_null($this->$name) && !empty($constant) && defined($constant)) {
84
                $this->$name = constant($constant);
85
            }
86
        }
87
    }
88
89
    /**
90
     * Zapíše zprávu do logu.
91
     *
92
     * @param string $message zpráva
93
     * @param string $type    typ zprávy (info|warning|success|error|*)
94
     *
95
     * @return bool byl report zapsán ?
96
     */
97
    public function addToLog($message, $type = 'message')
98
    {
99
        $logged = false;
100
        if (isset($this->logger) && is_object($this->logger)) {
101
            $this->logger->addToLog($this->getObjectName(), $message, $type);
102
        } else {
103
            $logged = Shared::logger()->addToLog($this->getObjectName(),
104
                $message, $type);
105
        }
106
107
        return $logged;
108
    }
109
110
    /**
111
     * Přidá zprávu do sdíleného zásobníku pro zobrazení uživateli.
112
     *
113
     * @param string $message  Text zprávy
114
     * @param string $type     Fronta zpráv (warning|info|error|success)
115
     *
116
     * @return 
117
     */
118
    public function addStatusMessage($message, $type = 'info')
119
    {
120
        return $this->easeShared->takeMessage(new Logger\Message($message,
0 ignored issues
show
Bug introduced by
Are you sure the usage of $this->easeShared->takeM...ype, get_class($this))) targeting Ease\Shared::takeMessage() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
121
                    $type, get_class($this)));
122
    }
123
124
    /**
125
     * Obtain Status Messages
126
     *
127
     * @param bool $clean Remove messages from strack ?
128
     *
129
     * @return array
130
     */
131
    public function getStatusMessages($clean = false)
132
    {
133
        $messages = $this->easeShared->getStatusMessages();
134
        if ($clean) {
135
            $this->easeShared->cleanMessages();
136
        }
137
        return $messages;
138
    }
139
140
}
141