Completed
Push — GildedRose/php ( 8e5d5b )
by
unknown
04:03
created

GildedRose   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 20
lcom 1
cbo 0
dl 0
loc 58
ccs 18
cts 30
cp 0.6
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
D update_quality() 0 49 19
1
<?php
2
3
namespace Kata\GildedRoseKata;
4
5
class GildedRose {
6
7
    private $items;
8
9 1
    function __construct($items) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
10 1
        $this->items = $items;
11 1
    }
12
13 1
    function update_quality() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
14 1
        foreach ($this->items as $item) {
15 1
            if ($item->name != 'Aged Brie' and $item->name != 'Backstage passes to a TAFKAL80ETC concert') {
0 ignored issues
show
Comprehensibility Best Practice introduced by
Using logical operators such as and instead of && is generally not recommended.

PHP has two types of connecting operators (logical operators, and boolean operators):

  Logical Operators Boolean Operator
AND - meaning and &&
OR - meaning or ||

The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like &&, or ||.

Let’s take a look at a few examples:

// Logical operators have lower precedence:
$f = false or true;

// is executed like this:
($f = false) or true;


// Boolean operators have higher precedence:
$f = false || true;

// is executed like this:
$f = (false || true);

Logical Operators are used for Control-Flow

One case where you explicitly want to use logical operators is for control-flow such as this:

$x === 5
    or die('$x must be 5.');

// Instead of
if ($x !== 5) {
    die('$x must be 5.');
}

Since die introduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined with throw at this point:

// The following is currently a parse error.
$x === 5
    or throw new RuntimeException('$x must be 5.');

These limitations lead to logical operators rarely being of use in current PHP code.

Loading history...
16 1
                if ($item->quality > 0) {
17
                    if ($item->name != 'Sulfuras, Hand of Ragnaros') {
18 1
                        $item->quality = $item->quality - 1;
19
                    }
20
                }
21
            } else {
22
                if ($item->quality < 50) {
23
                    $item->quality = $item->quality + 1;
24
                    if ($item->name == 'Backstage passes to a TAFKAL80ETC concert') {
25
                        if ($item->sell_in < 11) {
26
                            if ($item->quality < 50) {
27
                                $item->quality = $item->quality + 1;
28
                            }
29
                        }
30
                        if ($item->sell_in < 6) {
31
                            if ($item->quality < 50) {
32
                                $item->quality = $item->quality + 1;
33
                            }
34
                        }
35
                    }
36
                }
37
            }
38
39 1
            if ($item->name != 'Sulfuras, Hand of Ragnaros') {
40 1
                $item->sell_in = $item->sell_in - 1;
41
            }
42
43 1
            if ($item->sell_in < 0) {
44 1
                if ($item->name != 'Aged Brie') {
45 1
                    if ($item->name != 'Backstage passes to a TAFKAL80ETC concert') {
46 1
                        if ($item->quality > 0) {
47
                            if ($item->name != 'Sulfuras, Hand of Ragnaros') {
48 1
                                $item->quality = $item->quality - 1;
49
                            }
50
                        }
51
                    } else {
52 1
                        $item->quality = $item->quality - $item->quality;
53
                    }
54
                } else {
55
                    if ($item->quality < 50) {
56 1
                        $item->quality = $item->quality + 1;
57
                    }
58
                }
59
            }
60
        }
61 1
    }
62
}
63
64
65