SMS   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
require_once __DIR__.'/../vendor/autoload.php';
6
7
use Scalp\PatternMatching\CaseClass;
8
use Scalp\PatternMatching\Deconstruction;
9
use function Scalp\PatternMatching\match;
10
use function Scalp\PatternMatching\Type;
0 ignored issues
show
Bug introduced by
The type Scalp\PatternMatching\Type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use function Scalp\PatternMatching\Any;
0 ignored issues
show
Bug introduced by
The type Scalp\PatternMatching\Any was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use function Scalp\println;
0 ignored issues
show
Bug introduced by
The type Scalp\println was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use function Scalp\papply;
0 ignored issues
show
Bug introduced by
The type Scalp\papply was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use const Scalp\__;
0 ignored issues
show
Bug introduced by
The type Scalp\__ was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use const Scalp\concat;
0 ignored issues
show
Bug introduced by
The type Scalp\concat was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
17
abstract class Notification implements CaseClass
18
{
19
}
20
21
final class Email extends Notification
22
{
23
    use Deconstruction;
24
25
    private $sender;
26
    private $title;
27
    private $body;
28
29
    public function __construct(string $sender, string $title, string $body)
30
    {
31
        $this->construct($sender, $title, $body);
32
33
        $this->sender = $sender;
34
        $this->title = $title;
35
        $this->body = $body;
36
    }
37
}
38
39
final class SMS extends Notification
40
{
41
    use Deconstruction;
42
43
    private $caller;
44
    private $message;
45
46
    public function __construct(string $caller, string $message)
47
    {
48
        $this->construct($caller, $message);
49
50
        $this->caller = $caller;
51
        $this->message = $message;
52
    }
53
}
54
55
final class VoiceRecording extends Notification
56
{
57
    use Deconstruction;
58
59
    private $contactName;
60
    private $link;
61
62
    public function __construct(string $contactName, string $link)
63
    {
64
        $this->construct($contactName, $link);
65
66
        $this->contactName = $contactName;
67
        $this->link = $link;
68
    }
69
}
70
71
function showNotification(Notification $notification): string
72
{
73
    return match($notification)
74
        ->case(
75
            Type(Email::class, Type('string')->bind(), Type('string')->bind(), Any()),
0 ignored issues
show
Unused Code introduced by
The call to type() has too many arguments starting with Type('string')->bind(). ( Ignorable by Annotation )

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

75
            /** @scrutinizer ignore-call */ Type(Email::class, Type('string')->bind(), Type('string')->bind(), Any()),

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...
Bug introduced by
Type(Email::class, Type(...tring')->bind(), Any()) of type string is incompatible with the type Scalp\PatternMatching\Pattern\Pattern expected by parameter $pattern of Scalp\PatternMatching\Un...vedMatchSubject::case(). ( Ignorable by Annotation )

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

75
            /** @scrutinizer ignore-type */ Type(Email::class, Type('string')->bind(), Type('string')->bind(), Any()),
Loading history...
76
            papply(concat, 'You got an email from ', __, 'with title: ', __)
77
        )
78
        ->case(
79
            Type(SMS::class, Type('string')->bind(), Type('string')->bind()),
0 ignored issues
show
Bug introduced by
Type(SMS::class, Type('s...Type('string')->bind()) of type string is incompatible with the type Scalp\PatternMatching\Pattern\Pattern expected by parameter $pattern of Scalp\PatternMatching\MatchSubject::case(). ( Ignorable by Annotation )

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

79
            /** @scrutinizer ignore-type */ Type(SMS::class, Type('string')->bind(), Type('string')->bind()),
Loading history...
80
            papply(concat, 'You got an SMS from ', __, '! Message: ', __)
81
        )
82
        ->case(
83
            Type(VoiceRecording::class, Type('string')->bind(), Type('string')->bind()),
84
            papply(concat, 'You received a Voice Recording from ', __, '! Click the link to hear it: ', __)
85
        )
86
        ->done();
87
}
88
89
$someSms = new SMS('12345', 'Are you there?');
90
$someVoiceRecording = new VoiceRecording('Tom', 'voicerecording.org/id/123');
91
92
println(showNotification($someSms));
93
println(showNotification($someVoiceRecording));
94