Completed
Push — develop ( 168e99...0122be )
by
unknown
18:37 queued 07:11
created

EntityTrait::notEmpty()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 33
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 33
rs 5.3846
cc 8
eloc 16
nc 11
nop 2
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
7
 * @license   MIT
8
 */
9
10
/** Core Entitys */
11
namespace Core\Entity;
12
13
use Core\Entity\Exception\OutOfBoundsException;
14
15
/**
16
 * Implementation of \Core\Entity\EntityInterface.
17
 *
18
 * Provides some magic function for accessing properties
19
 * as class members, mirroring these calls to the
20
 * getter and setter methods.
21
 *
22
 */
23
trait EntityTrait
24
{
25
    public function notEmpty($property, array $args=[])
0 ignored issues
show
Coding Style introduced by
function notEmpty() does not seem to conform to the naming convention (^(?:is|has|should|may|supports)).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
26
    {
27
        $method = "get$property";
28
29
        if (!method_exists($this, $method)) {
30
            throw new OutOfBoundsException("'$property' is not a valid property of '" . get_class($this) . "'");
31
        }
32
33
        $value = count($args)
34
            ? call_user_func_array([ $this, $method ], $args)
35
            : $this->$method();
36
37
        if (null === $value) { // is_scalar does not consider 'null' to be scalar value.
38
            return false;
39
        }
40
41
        if (is_scalar($value) || is_array($value)) {
42
            return !empty($value);
43
        }
44
45
        if (is_resource($value)) {
46
            return true;
47
        }
48
49
        /*
50
         * $value must be an object.
51
         */
52
        if ($value instanceOf \Countable) {
53
            return !(bool) count($value);
54
        }
55
56
        return false;
57
    }
58
}
59