Completed
Pull Request — master (#74)
by Phecho
05:50
created

CommentsController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A createAction() 0 19 2
1
<?php
2
3
/*
4
 * This file is part of Gitamin.
5
 * 
6
 * Copyright (C) 2015-2016 The Gitamin Team
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 Gitamin\Http\Controllers\Projects;
13
14
use Gitamin\Commands\Comment\AddCommentCommand;
15
use Gitamin\Http\Controllers\Controller;
16
use Gitamin\Models\Comment;
17
use Gitamin\Models\Project;
18
use GrahamCampbell\Binput\Facades\Binput;
19
use Illuminate\Support\Facades\Auth;
20
use Illuminate\Support\Facades\Redirect;
21
use Illuminate\Support\Facades\View;
22
23
class CommentsController extends Controller
24
{
25
    /**
26
     * Show the form for creating a new resource.
27
     *
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function createAction($owner_path, $project_path)
31
    {
32
        $project = Project::findByPath($owner_path, $project_path);
33
        $commentData = Binput::get('comment');
34
35
        try {
36
            $commentData['author_id'] = Auth::user()->id;
37
            $commentData['project_id'] = $project->id;
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<Gitamin\Models\User>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
38
            $comment = $this->dispatchFromArray(AddCommentCommand::class, $commentData);
0 ignored issues
show
Unused Code introduced by
$comment 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...
39
        } catch (ValidationException $e) {
0 ignored issues
show
Bug introduced by
The class Gitamin\Http\Controllers...cts\ValidationException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
40
            return Redirect::route('projects.issue_show', ['owner' => $owner_path, 'project' => $project_path, 'issue' => $commentData['target_id']])
41
                ->withInput(Binput::all())
42
                ->withTitle(sprintf('%s %s', trans('dashboard.notifications.whoops'), trans('dashboard.issues.new.failure')))
43
                ->withErrors($e->getMessageBag());
44
        }
45
46
        return Redirect::route('projects.issue_show', ['owner' => $owner_path, 'project' => $project_path, 'issue' => $commentData['target_id']])
47
            ->withSuccess(sprintf('%s %s', trans('dashboard.notifications.awesome'), trans('dashboard.issues.new.success')));
48
    }
49
}
50