Completed
Push — master ( efa9b4...b05f68 )
by wen
05:55
created

src/Display/ColumnFactory.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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