Passed
Push — master ( 327c88...be0116 )
by hugh
06:54
created

UserMessageText::eq()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: hugh.li
5
 * Date: 2022/2/24
6
 * Time: 17:35
7
 */
8
9
namespace HughCube\Laravel\WeChat\Message\Event;
10
11
use HughCube\Laravel\WeChat\Contracts\Message\Event\UserMessageText as Contract;
12
use HughCube\PUrl\Url;
13
use Illuminate\Support\Str;
14
15
class UserMessageText extends Event implements Contract
16
{
17
    public function getContent($trim = true): string
18
    {
19
        $content = $this->getMessage('Content');
20
21
        return $trim ? trim($content) : $content;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $trim ? trim($content) : $content could return the type array|null which is incompatible with the type-hinted return string. Consider adding an additional type-check to rule them out.
Loading history...
Bug introduced by
It seems like $content can also be of type array and null; however, parameter $string of trim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
        return $trim ? trim(/** @scrutinizer ignore-type */ $content) : $content;
Loading history...
22
    }
23
24
    public function is($pattern, $trim = true): bool
25
    {
26
        return Str::is($pattern, $this->getContent($trim));
27
    }
28
29
    public function eq($string, $trim = true): bool
30
    {
31
        return $string === $this->getContent($trim);
32
    }
33
34
    public function contains($needles, $ignoreCase = false, $trim = true): bool
35
    {
36
        return Str::contains($this->getContent($trim), $needles, $ignoreCase);
0 ignored issues
show
Unused Code introduced by
The call to Illuminate\Support\Str::contains() has too many arguments starting with $ignoreCase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

36
        return Str::/** @scrutinizer ignore-call */ contains($this->getContent($trim), $needles, $ignoreCase);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
37
    }
38
39
    public function getUrl(): ?Url
40
    {
41
        return Url::parse($this->getContent());
42
    }
43
}
44