Karma100Achieve   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * This file is part of GitterBot package.
4
 *
5
 * @author Serafim <[email protected]>
6
 * @date 11.10.2015 6:07
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Domains\Bot\Achievements;
12
13
use Domains\Karma;
14
use Interfaces\Gitter\Achieve\AbstractAchieve;
15
16
/**
17
 * Class Karma100Achieve
18
 */
19 View Code Duplication
class Karma100Achieve extends AbstractAchieve
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
20
{
21
    /**
22
     * @var string
23
     */
24
    public $title = 'Благодетель';
25
26
    /**
27
     * @var string
28
     */
29
    public $description = 'Набрать 100 кармы.';
30
31
    /**
32
     * @var string
33
     */
34
    public $image = '//karma.laravel.su/img/achievements/karma-100.gif';
35
36
    /**
37
     * @throws \LogicException
38
     */
39
    public function handle()
40
    {
41
        Karma::created(function (Karma $karma) {
42
            $count = $karma->target->karma->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $karma->target->karma (of type array<integer,object<Domains\Karma>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
43
44
            if ($count === 100) {
45
                $this->create($karma->target, $karma->created_at);
0 ignored issues
show
Documentation introduced by
$karma->created_at is of type string, but the function expects a null|object<Carbon\Carbon>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
            }
47
        });
48
    }
49
}
50