Completed
Push — develop-3.0 ( 4fe777...24fc5d )
by Mohamed
09:15
created

ComposerServiceProvider   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 4
dl 0
loc 53
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 15 2
B loadProjectDefaultData() 0 14 5
A register() 0 3 1
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Providers;
13
14
use Illuminate\Bus\Dispatcher;
15
use Illuminate\Support\Collection;
16
use Illuminate\Support\ServiceProvider;
17
use Illuminate\View\View;
18
use Tinyissue\Extensions\Auth\LoggedUser;
19
use Tinyissue\Form\ExportIssues;
20
use Tinyissue\Model\Project;
21
22
/**
23
 * ComposerServiceProvider is the view service provider binding data to specific views.
24
 *
25
 * @author Mohamed Alsharaf <[email protected]>
26
 */
27
class ComposerServiceProvider extends ServiceProvider
28
{
29
    use LoggedUser;
30
31
    /**
32
     * Bootstrap any application services.
33
     *
34
     * @param \Illuminate\Bus\Dispatcher $dispatcher
35
     */
36
    public function boot(Dispatcher $dispatcher)
0 ignored issues
show
Unused Code introduced by
The parameter $dispatcher is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
37
    {
38
        // Add export form to project sidebar
39
        // @todo review this
40
        \View::composer('layouts/sidebar/project', function (View $view) {
41
            $exportForm = new ExportIssues($this->app);
0 ignored issues
show
Compatibility introduced by
$this->app of type object<Illuminate\Contra...Foundation\Application> is not a sub-type of object<Illuminate\Foundation\Application>. It seems like you assume a concrete implementation of the interface Illuminate\Contracts\Foundation\Application to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
42
            $exportForm->setup(['project' => $view->project]);
43
44
            if ($view->project instanceof Project) {
45
                $this->loadProjectDefaultData($view->project, $view);
46
            }
47
48
            $view->with('exportForm', $exportForm);
49
        });
50
    }
51
52
    /**
53
     * Load any variables that are default to project side bar.
54
     *
55
     * @param Project $project
56
     * @param View    $view
57
     */
58
    protected function loadProjectDefaultData(Project $project, View $view)
59
    {
60
        if (!$view->offsetExists('closed_issues_count')) {
61
            $view->with('closed_issues_count', $project->countClosedIssues($this->getLoggedUser()));
0 ignored issues
show
Bug introduced by
The method countClosedIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
62
        }
63
64
        if (!$view->offsetExists('open_issues_count')) {
65
            $view->with('open_issues_count', $project->countOpenIssues($this->getLoggedUser()));
0 ignored issues
show
Bug introduced by
The method countOpenIssues() does not exist on Tinyissue\Model\Project. Did you maybe mean issues()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
66
        }
67
68
        if (!$view->offsetExists('project_users') || !$view->project_users instanceof Collection) {
69
            $view->with('project_users', $project->getUsers());
0 ignored issues
show
Documentation Bug introduced by
The method getUsers does not exist on object<Tinyissue\Model\Project>? 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...
70
        }
71
    }
72
73
    /**
74
     * Register any application services.
75
     */
76
    public function register()
77
    {
78
    }
79
}
80