ResponseObject   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 128
ccs 40
cts 40
cp 1
rs 10
wmc 21
lcom 1
cbo 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A setStatus() 0 4 2
A setCode() 0 4 2
A setMsg() 0 4 2
A setUID() 0 4 2
A setUsername() 0 4 2
A setTime() 0 4 1
A setContext() 0 4 1
A setLevel() 0 4 1
A getStatus() 0 4 1
A getCode() 0 4 1
A getMsg() 0 4 1
A getUID() 0 4 1
A getUsername() 0 4 1
A getTime() 0 4 1
A getContext() 0 4 1
A getLevel() 0 4 1
1
<?php
2
/********************************************************************
3
 * Created by:	Marko Kungla @ OkramLabs on Aug 6, 2012 - 9:12:38
4
 * Contact:		[email protected] - https://okramlabs.com
5
 * @copyright:	2015 OkramLabs - https://okramlabs.com
6
 * @license		MIT
7
 *
8
 * Package name: libhowi-filesystem
9
 * @category	 HOWI3
10
 * @package		 libhowi
11
 * @subpackage	 filesystem
12
 * 
13
 * Lang:		PHP
14
 * Encoding:	UTF-8
15
 * File:		ResponseObject.inc
16
 * @link		https://github.com/okramlabs/libhowi-filesystem
17
 ********************************************************************
18
 * Contributors:
19
 * @author		Marko Kungla <[email protected]>
20
 *  	Github:	https://github.com/mkungla
21
 ********************************************************************
22
 * Comments:
23
 *     1. This response trait is adjusted to follow structure of PSR-3. psr/log
24
 *     see - https://github.com/php-fig/log
25
 */
26
namespace HOWI3\libhowi\Filesystem\Commons;
27
28
final class ResponseObject
29
{
30
31
    /**
32
     * Filesystem status
33
     *
34
     * All filesystem methods have true/false states which are stored here
35
     * so it will only change when any messages are logged above minimum loglevel
36
     *
37
     * @var int $status
38
     */
39
    private $status = false;
40
41
    /**
42
     * Last log code
43
     *
44
     * Last logged message code
45
     *
46
     * @var int $code
47
     */
48
    private $code = 0;
49
50
    /**
51
     * Last log message
52
     *
53
     * Defaults to OK and further holds last logged message
54
     *
55
     * @var string $message
56
     */
57
    private $message = 'OK';
58
59
    /**
60
     * Following is optional to have user id and username attached to log
61
     * Following can be anything you want for example your currently logged in
62
     * user info or system user running the script.
63
     *
64
     * @var unknown
65
     */
66
    private $UID = 0;
67
68
    private $username = 'anonymous';
69
70
    private $context;
71
72
    private $level;
73
74
75 731
    public function setStatus($arg)
76
    {
77 731
        $this->status = is_bool($arg) ? $arg : false;
0 ignored issues
show
Documentation Bug introduced by
The property $status was declared of type integer, but is_bool($arg) ? $arg : false is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
78 731
    }
79
80 731
    public function setCode($code)
81
    {
82 731
        $this->code = is_int($code) ? $code : 0;
83 731
    }
84
85 731
    public function setMsg($msg)
86
    {
87 731
        $this->message = is_string($msg) ? $msg : 'BUG';
88 731
    }
89
90 731
    public function setUID($UID)
91
    {
92 731
        $this->UID = is_int($UID) ? $UID : 'BUG';
0 ignored issues
show
Documentation Bug introduced by
It seems like is_int($UID) ? $UID : 'BUG' of type integer or string is incompatible with the declared type object<HOWI3\libhowi\Filesystem\Commons\unknown> of property $UID.

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...
93 731
    }
94
95 731
    public function setUsername($username)
96
    {
97 731
        $this->username = is_string($username) ? $username : 'BUG';
98 731
    }
99
100 731
    public function setTime()
101
    {
102 731
        $this->microtime = microtime(true);
0 ignored issues
show
Bug introduced by
The property microtime does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
103 731
    }
104
105 731
    public function setContext($context)
106
    {
107 731
        $this->context = $context;
108 731
    }
109
110 731
    public function setLevel($level)
111
    {
112 731
        $this->level = $level;
113 731
    }
114
115
116 33
    public function getStatus()
117
    {
118 33
        return $this->status;
119
    }
120
121 84
    public function getCode()
122
    {
123 84
        return $this->code;
124
    }
125
126 66
    public function getMsg()
127
    {
128 66
        return $this->message;
129
    }
130
131 3
    public function getUID()
132
    {
133 3
        return $this->UID;
134
    }
135
136 3
    public function getUsername()
137
    {
138 3
        return $this->username;
139
    }
140
141 63
    public function getTime()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
142
    {
143 63
        return $this->microtime;
144
    }
145
146 3
    public function getContext()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
147
    {
148 3
        return $this->context;
149
    }
150
151 3
    public function getLevel()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
152
    {
153 3
        return $this->level;
154
    }
155
}
156