Manufacturer::desc()   B
last analyzed

Complexity

Conditions 8
Paths 32

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 6
c 1
b 0
f 0
nc 32
nop 0
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 8
rs 8.4444
1
<?php
2
3
namespace kalanis\simple_vin\Support;
4
5
6
final class Manufacturer implements \Stringable
7
{
8 8
    public function __construct(
9
        public readonly string $code,
10
        public readonly string $brand,
11
        public readonly string $types = '',
12
        public readonly string $model = '',
13
        public readonly string $manufacturer = '',
14
        public readonly string $country = '',
15
        public readonly ?int   $from = null,
16
        public readonly ?int   $to = null,
17
        public readonly string $notes = '',
18
        public readonly bool   $canCompareDates = false,
19
    )
20
    {
21 8
    }
22
23 1
    public function desc(): string
24
    {
25 1
        return
26 1
            ($this->manufacturer ? $this->manufacturer . ' - ' : '')
27 1
            . $this->brand . ' ' . $this->model
28 1
            . ($this->types ? (' ' . $this->types) : '')
29 1
            . (($this->from || $this->to) ? (' (' . ($this->from ?: '') . '-' . ($this->to ?: '') . ')') : '')
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->from of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
Bug Best Practice introduced by
The expression $this->to of type integer|null is loosely compared to true; this is ambiguous if the integer can be 0. You might want to explicitly use !== null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
30 1
            . ($this->country ? ', ' . $this->country : '');
31
    }
32
33 1
    public function __toString(): string
34
    {
35 1
        return $this->desc();
36
    }
37
}
38