Completed
Push — master ( 1aa149...14784f )
by Richard
06:07
created

ButNot::__call()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2.032

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 13
loc 13
ccs 8
cts 10
cp 0.8
rs 9.4285
cc 2
eloc 9
nc 2
nop 2
crap 2.032
1
<?php
2
/******************************************************************************
3
 * An implementation of dicto (scg.unibe.ch/dicto) in and for PHP.
4
 * 
5
 * Copyright (c) 2016 Richard Klees <[email protected]>
6
 *
7
 * This software is licensed under The MIT License. You should have received 
8
 * a copy of the licence along with the code.
9
 */
10
11
namespace Lechimp\Dicto\Definition\Fluid;
12
use Lechimp\Dicto\Definition\Variables as Vars;
13
14
/**
15
 * Provides fluid interface to as_well_as().
16
 */
17 View Code Duplication
class ButNot extends Base {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18 38
    public function __call($name, $arguments) {
19 38
        if (count($arguments) != 0) {
20
            # ToDo: This is used in Dicto::__callstatic as well.
21
            throw new \InvalidArgumentException(
22
                "No arguments are allowed for the reference to a variable.");
23
        }
24
25 38
        $left = $this->rt->get_current_var();
26 38
        $right = $this->rt->get_var($name);
27 38
        assert('$left instanceof \\Lechimp\\Dicto\\Definition\\Variables\\Variable');
28 38
        $this->rt->current_var_is(
29 38
            new Vars\ButNot($this->rt->get_current_var_name(), $left, $right));
0 ignored issues
show
Bug introduced by
It seems like $left defined by $this->rt->get_current_var() on line 25 can be null; however, Lechimp\Dicto\Definition...s\ButNot::__construct() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
30 38
    }
31
}
32