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

Thanks10Karma0Achieve   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 3
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 Thanks10Karma0Achieve
18
 */
19
class Thanks10Karma0Achieve extends AbstractAchieve
20
{
21
    /**
22
     * @var string
23
     */
24
    public $title = 'Полный паразец!';
25
26
    /**
27
     * @var string
28
     */
29
    public $description = 'Сказать 10 раз "спасибо" не имея ни единой благодарности.';
30
31
    /**
32
     * @var string
33
     */
34
    public $image = '//karma.laravel.su/img/achievements/thanks-10-karma-0.gif';
35
36
    /**
37
     * @throws \LogicException
38
     */
39
    public function handle()
40
    {
41
        Karma::created(function (Karma $karma) {
42
            $userThanks = $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
            $userKarma = $karma->user->karma->count();
0 ignored issues
show
Bug introduced by
The method count cannot be called on $karma->user->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...
44
45
            if ($userThanks === 10 && $userKarma === 0) {
46
                $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...
47
            }
48
        });
49
    }
50
}
51