Passed
Pull Request — master (#2)
by
unknown
07:29
created

Scream::getScreamErrorMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php 
2
3
namespace Zeeshanu\Yell;
4
5
use Zeeshanu\Yell\Exceptions\UndefinedPropertyException;
6
7
trait Scream
8
{
9
    /**
10
     * Check if the property that user trying to get exists or not. If the property
11
     * doesn't exist then throw an exception.
12
     * 
13
     * @param  string $propertyName
14
     * @throws UndefinedPropertyException
15
     * 
16
     * @return void
17
     */
18
    public function __get($propertyName)
19
    {
20
        if (! property_exists($this, $propertyName)) {
21
            throw new UndefinedPropertyException($this->getScreamErrorMessage("get"));
0 ignored issues
show
Bug introduced by
The call to getScreamErrorMessage() misses a required argument $propertyName.

This check looks for function calls that miss required arguments.

Loading history...
22
        }
23
    }
24
25
    /**
26
     * Check if the property that user trying to set exists or not. If the property
27
     * doesn't exist then throw an exception.
28
     * 
29
     * @param  string $propertyName
30
     * @param  mixed $value
31
     * @throws UndefinedPropertyException
32
     * 
33
     * @return void
34
     */
35
    public function __set($propertyName, $value)
0 ignored issues
show
Unused Code introduced by
The parameter $value is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        if (! property_exists($this, $propertyName)) {
38
            throw new UndefinedPropertyException($this->getScreamErrorMessage("set", $propertyName));
39
        }   
40
    }
41
42
    /**
43
     * Generates an exception message.
44
     * 
45
     * @param  string $errorType
46
     * @param  string $propertyName
47
     * @return string Exception message
48
     */
49
    public function getScreamErrorMessage($errorType, $propertyName)
50
    {
51
        return 'Trying to ' . $errorType . ' undefined property $' . $propertyName . ' in class ' . get_class($this);
52
    }
53
}
54