Completed
Push — master ( c1ce98...b3e799 )
by Kirill
03:09
created

Thanks20Achieve::handle()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 10
loc 10
rs 9.4285
cc 2
eloc 5
nc 1
nop 0
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 Thanks20Achieve
18
 */
19 View Code Duplication
class Thanks20Achieve 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 = 'Высказать 20 благодарностей.';
30
31
    /**
32
     * @var string
33
     */
34
    public $image = '//karma.laravel.su/img/achievements/thanks-20.gif';
35
36
    /**
37
     * @throws \LogicException
38
     */
39
    public function handle()
40
    {
41
        Karma::created(function (Karma $karma) {
42
            $count = $karma->user->thanks->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $karma->user->thanks (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 === 20) {
45
                $this->create($karma->user, $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