TableName   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A toString() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Puzzle\QueryBuilder\Queries\Snippets;
6
7
use Puzzle\QueryBuilder\Snippet;
8
9
class TableName implements Snippet
10
{
11
    private
12
        $tableName,
1 ignored issue
show
Coding Style introduced by
It is generally advisable to only define one property per statement.

Only declaring a single property per statement allows you to later on add doc comments more easily.

It is also recommended by PSR2, so it is a common style that many people expect.

Loading history...
Coding Style introduced by
The visibility should be declared for property $tableName.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
13
        $alias;
14
15 73
    public function __construct(?string $tableName, ?string $alias = null)
16
    {
17 73
        if(empty($tableName))
18
        {
19 6
            throw new \InvalidArgumentException('Empty table name.');
20
        }
21
22 67
        $this->tableName = $tableName;
23
24 67
        $this->alias = (string) $alias;
25 67
    }
26
27 65
    public function toString(): string
28
    {
29 65
        if(empty($this->alias))
30
        {
31 32
            return $this->tableName;
32
        }
33
34 35
        return sprintf('%s AS %s', $this->tableName, $this->alias);
35
    }
36
}
37