GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

BattleCalcController::getArmyBase()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 6
nc 1
nop 2
1
<?php namespace Xaoc303\BattleCalc;
2
3
use View;
4
use Config;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Xaoc303\BattleCalc\Config.

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...
5
use Lang;
6
use Input;
7
8
/**
9
 * Class BattleCalcController
10
 * @package Xaoc303\BattleCalc
11
 */
12
class BattleCalcController extends \Controller
13
{
14
    /**
15
     * getIndex
16
     *
17
     * @return string
18
     */
19
    public function getIndex()
20
    {
21
        return View::make('battle-calc::views.index')
22
            ->with('title', __CLASS__)
23
            ->nest('content', 'battle-calc::views.calc', ['races' => Lang::get('battle-calc::races')]);
24
    }
25
26
    /**
27
     * getArmyBase
28
     *
29
     * @param integer $id_army
30
     * @param integer $race
31
     * @return string
32
     */
33
    public function getArmyBase($id_army, $race)
34
    {
35
        $units = Config::get('battle-calc::units');
36
        return View::make('battle-calc::views.getarmybase')
37
            ->with('units', array_where($units, function($key, $value) use ($race) {
38
                return $value['race_id'] == $race;
39
            }))
40
            ->with('id_army', (int) $id_army);
41
    }
42
43
    /**
44
     * getCalculation
45
     *
46
     * @return string
47
     */
48
    public function getCalculation()
49
    {
50
        $army_1 = Input::get('army-1', []);
51
        $army_2 = Input::get('army-2', []);
52
53
        return (new BattleCalc())->calculation($army_1, $army_2);
54
    }
55
}
56