Passed
Push — master ( 179943...1193c4 )
by Darko
09:13
created

AbstractCategorizationPipe::shouldSkip()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace App\Services\Categorization\Pipes;
4
5
use App\Services\Categorization\CategorizationResult;
6
use App\Services\Categorization\ReleaseContext;
7
use Closure;
8
9
/**
10
 * Base class for categorization pipe handlers.
11
 *
12
 * Each pipe is responsible for categorizing a specific type of release.
13
 */
14
abstract class AbstractCategorizationPipe
15
{
16
    protected int $priority = 50;
17
18
    /**
19
     * Handle the categorization request.
20
     */
21
    public function handle(CategorizationPassable $passable, Closure $next): CategorizationPassable
22
    {
23
        // If we already have a high-confidence match, skip processing
24
        if ($passable->shouldStopProcessing()) {
25
            return $next($passable);
26
        }
27
28
        // Skip if this categorizer shouldn't process this release
29
        if ($this->shouldSkip($passable->context)) {
30
            return $next($passable);
31
        }
32
33
        // Attempt categorization
34
        $result = $this->categorize($passable->context);
35
36
        // Update the best result
37
        $passable->updateBestResult($result, $this->getName());
38
39
        return $next($passable);
40
    }
41
42
    /**
43
     * Get the priority of this categorizer (lower = higher priority).
44
     */
45
    public function getPriority(): int
46
    {
47
        return $this->priority;
48
    }
49
50
    /**
51
     * Get the name of this categorizer for debugging/logging.
52
     */
53
    abstract public function getName(): string;
54
55
    /**
56
     * Attempt to categorize the given release.
57
     */
58
    abstract protected function categorize(ReleaseContext $context): CategorizationResult;
59
60
    /**
61
     * Check if this categorizer should be skipped for the given context.
62
     */
63
    protected function shouldSkip(ReleaseContext $context): bool
0 ignored issues
show
Unused Code introduced by
The parameter $context is not used and could be removed. ( Ignorable by Annotation )

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

63
    protected function shouldSkip(/** @scrutinizer ignore-unused */ ReleaseContext $context): bool

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
64
    {
65
        return false;
66
    }
67
68
    /**
69
     * Create a successful categorization result.
70
     */
71
    protected function matched(int $categoryId, float $confidence, string $matchedBy, array $debug = []): CategorizationResult
72
    {
73
        return new CategorizationResult($categoryId, $confidence, $matchedBy, $debug);
74
    }
75
76
    /**
77
     * Create a no-match result.
78
     */
79
    protected function noMatch(): CategorizationResult
80
    {
81
        return CategorizationResult::noMatch();
82
    }
83
}
84
85