AppServiceProvider::composer()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace App\Providers;
4
5
use App\Model\Update\BarNotification;
6
use Illuminate\Queue\Events\JobFailed;
7
use Illuminate\Support\ServiceProvider;
8
use Queue;
9
use View;
10
11
class AppServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * Register any application services.
15
     *
16
     * This service provider is a great spot to register your various container
17
     * bindings with the application. As you can see, we are registering our
18
     * "Registrar" implementation here. You can add your own bindings too!
19
     *
20
     * @return void
21
     */
22
    public function register()
23
    {
24
        $this->app->bind('Illuminate\Contracts\Auth\Registrar');
25
        require_once __DIR__.'/../Http/helpers.php';
26
    }
27
28
    public function boot()
29
    {
30
        Queue::failing(function (JobFailed $event) {
31
            loging('Failed Job - '.$event->connectionName, json_encode($event->data));
32
            $failedid = $event->failedId;
0 ignored issues
show
Unused Code introduced by
$failedid is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
33
            //\Artisan::call('queue:retry',['id'=>[$failedid]]);
0 ignored issues
show
Unused Code Comprehensibility introduced by
87% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
34
        });
35
        // Please note the different namespace
36
        // and please add a \ in front of your classes in the global namespace
37
        \Event::listen('cron.collectJobs', function () {
38
            \Cron::add('example1', '* * * * *', function () {
39
                $this->index();
0 ignored issues
show
Documentation Bug introduced by
The method index does not exist on object<App\Providers\AppServiceProvider>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
40
41
                return 'No';
42
            });
43
44
            \Cron::add('example2', '*/2 * * * *', function () {
45
                // Do some crazy things successfully every two minute
46
            });
47
48
            \Cron::add('disabled job', '0 * * * *', function () {
49
                // Do some crazy things successfully every hour
50
            }, false);
51
        });
52
53
        $this->composer();
54
    }
55
56
    public function composer()
57
    {
58
        \View::composer('themes.default1.update.notification', function () {
59
            $notification = new BarNotification();
60
            $not = [
61
                'notification' => $notification->where('value', '!=', '')->get(),
0 ignored issues
show
Documentation Bug introduced by
The method where does not exist on object<App\Model\Update\BarNotification>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
62
            ];
63
            view()->share($not);
0 ignored issues
show
Bug introduced by
The method share does only exist in Illuminate\Contracts\View\Factory, but not in Illuminate\View\View.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
64
        });
65
    }
66
}
67