Completed
Branch develop-3.0 (ae28cb)
by Mohamed
08:28
created

loadProjectSideBarDefaultVariables()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 8
nop 2
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\Support\Collection;
15
use Illuminate\Support\ServiceProvider;
16
use Illuminate\View\View;
17
use Tinyissue\Extensions\Auth\LoggedUser;
18
use Tinyissue\Form\ExportIssues;
19
use Tinyissue\Model\Project;
20
21
/**
22
 * ComposerServiceProvider is the view service provider binding data to specific views.
23
 *
24
 * @author Mohamed Alsharaf <[email protected]>
25
 */
26
class ComposerServiceProvider extends ServiceProvider
27
{
28
    use LoggedUser;
29
30
    /**
31
     * Bootstrap any application services.
32
     */
33
    public function boot()
34
    {
35
        // Load variable into project side bar template
36
        \View::composer('layouts/sidebar/project', function (View $view) {
37
            $this->loadExportIssuesForm($view);
38
39
            $this->loadProjectSideBarDefaultVariables($view->project, $view);
40
        });
41
    }
42
43
    /**
44
     * Load any variables that are default to project side bar.
45
     *
46
     * @param Project $project
47
     * @param View    $view
48
     */
49
    protected function loadProjectSideBarDefaultVariables(Project $project, View $view)
50
    {
51
        if (!$view->offsetExists('closed_issues_count')) {
52
            $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...
53
        }
54
55
        if (!$view->offsetExists('open_issues_count')) {
56
            $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...
57
        }
58
59
        if (!$view->offsetExists('project_users') || !$view->project_users instanceof Collection) {
60
            $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...
61
        }
62
    }
63
64
    /**
65
     * Add export form to project sidebar.
66
     *
67
     * @param View $view
68
     *
69
     * @return void
70
     */
71
    protected function loadExportIssuesForm(View $view)
72
    {
73
        $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...
74
        $exportForm->setup(['project' => $view->project]);
75
76
        $view->with('exportForm', $exportForm);
77
    }
78
79
    /**
80
     * Register any application services.
81
     */
82
    public function register()
83
    {
84
    }
85
}
86