Test Failed
Pull Request — main (#342)
by Chema
08:14 queued 04:08
created

MissingClassDefinitionException::getSuggestions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 40
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 40
ccs 0
cts 0
cp 0
crap 2
rs 9.9666
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Gacela\Framework\ClassResolver\DocBlockService;
6
7
use RuntimeException;
8
9
final class MissingClassDefinitionException extends RuntimeException
10
{
11 3
    public static function missingDefinition(string $className, string $method, string $found): self
12
    {
13 3
        $suggestions = self::getSuggestions($method);
14 3
15
        return new self("
16
Missing the concrete return type for the method `{$method}()` (Found: `{$found}`).
17 3
18 3
Class: `{$className}`
19
20
Possible solutions:
21
{$suggestions}
22
23
Learn more: https://gacela-project.com/docs/service-resolution
24
");
25
    }
26
27
    private static function getSuggestions(string $method): string
28
    {
29
        $suggestions = [];
30
31
        // Add suggestion for using ServiceMap attribute
32
        $suggestions[] = "1. Use the #[ServiceMap] attribute (recommended - fastest):
33
34
   use Gacela\Framework\ClassResolver\Attribute\ServiceMap;
35
36
   #[ServiceMap('{$method}', YourClass::class)]
37
   final class YourFacade extends AbstractFacade
38
   {
39
       public function {$method}(): YourClass
40
       {
41
           return \$this->resolve(YourClass::class);
42
       }
43
   }";
44
45
        // Add suggestion for DocBlock
46
        $suggestions[] = "2. Add a DocBlock with the return type:
47
48
   /**
49
    * @method YourClass {$method}()
50
    */
51
   final class YourFacade extends AbstractFacade
52
   {
53
   }";
54
55
        // Add suggestion for inline type hint
56
        $suggestions[] = "3. Add an inline return type hint:
57
58
   final class YourFacade extends AbstractFacade
59
   {
60
       public function {$method}(): YourClass
61
       {
62
           return \$this->resolve(YourClass::class);
63
       }
64
   }";
65
66
        return implode("\n\n", $suggestions);
67
    }
68
}
69