Completed
Push — master ( 14f10a...6ec6b5 )
by Adam
02:31
created

GridBuilderTestCase   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 51
rs 10
wmc 2
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 13 1
A tearDown() 0 4 1
1
<?php
2
3
use Illuminate\Contracts\Container\Container;
4
use Orchestra\Testbench\TestCase;
5
use Collective\Html\HtmlBuilder;
6
use Collective\Html\FormBuilder;
7
use Illuminate\Http\Request;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Request.

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...
8
use Illuminate\Contracts\Validation\Factory as ValidationFactory;
9
use Illuminate\Contracts\View\Factory as ViewFactory;
10
use Boduch\Grid\GridHelper;
11
12
abstract class GridBuilderTestCase extends TestCase
1 ignored issue
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
13
{
14
    /**
15
     * @var ViewFactory
16
     */
17
    protected $view;
18
19
    /**
20
     * @var Request
21
     */
22
    protected $request;
23
24
    /**
25
     * @var GridHelper
26
     */
27
    protected $gridHelper;
28
29
    /**
30
     * @var ValidationFactory
31
     */
32
    protected $validator;
33
34
    /**
35
     * @var HtmlBuilder
36
     */
37
    protected $htmlBuilder;
38
39
    /**
40
     * @var FormBuilder
41
     */
42
    protected $formBuilder;
43
44
    public function setUp()
45
    {
46
        parent::setUp();
47
48
        $this->view = $this->app['view'];
49
        $this->request = $this->app['request'];
50
        $this->request->setSession($this->app['session.store']);
51
        $this->validator = $this->app['validator'];
52
        $this->htmlBuilder = new HtmlBuilder($this->app['url'], $this->view);
53
        $this->formBuilder = new FormBuilder($this->htmlBuilder, $this->app['url'], $this->view, $this->request->session()->getToken());
54
55
        $this->gridHelper = new GridHelper($this->request, $this->validator, $this->view, $this->htmlBuilder, $this->formBuilder);
56
    }
57
58
    public function tearDown()
59
    {
60
        parent::tearDown();
61
    }
62
}
63