Completed
Push — master ( 650783...0c9838 )
by wen
15:06
created

ColumnFactory   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
1
<?php
2
3
namespace Sco\Admin\Display;
4
5
use Sco\Admin\Contracts\Display\ColumnFactoryInterface;
6
use Sco\Admin\Traits\AliasBinder;
7
use Sco\Admin\Display\Columns\Custom;
8
use Sco\Admin\Display\Columns\DateTime;
9
use Sco\Admin\Display\Columns\Html;
10
use Sco\Admin\Display\Columns\Image;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Sco\Admin\Display\Image.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
11
use Sco\Admin\Display\Columns\Link;
12
use Sco\Admin\Display\Columns\Mapping;
13
use Sco\Admin\Display\Columns\Tags;
14
use Sco\Admin\Display\Columns\Text;
15
16
/**
17
 * @method static Text text($name, $label) text type column
18
 * @method static DateTime datetime($name, $label) datetime type column
19
 * @method static Image image($name, $label) image type column
20
 * @method static Link link($name, $label) link type column
21
 * @method static Custom custom($name, $label, \Closure $callback = null) custom type
22
 *         column
23
 * @method static Tags tags($name, $label) tags type column
24
 * @method static Html html($name, $label) tags type column
25
 * @method static Mapping mapping($name, $label, $mappings = null) mapping type column
26
 */
27
class ColumnFactory implements ColumnFactoryInterface
28
{
29
    use AliasBinder;
30
31
    public function __construct()
32
    {
33
        $this->register([
34
            'text'     => Text::class,
35
            'datetime' => DateTime::class,
36
            'image'    => Image::class,
37
            'link'     => Link::class,
38
            'tags'     => Tags::class,
39
            'custom'   => Custom::class,
40
            'mapping'  => Mapping::class,
41
            'html'     => Html::class,
42
        ]);
43
    }
44
}
45