1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leonidas\Console\Library; |
4
|
|
|
|
5
|
|
|
use Leonidas\Console\Library\Abstracts\AbstractClassPrinter; |
6
|
|
|
use Leonidas\Contracts\System\Schema\Comment\CommentConverterInterface; |
7
|
|
|
use Leonidas\Contracts\System\Schema\Post\PostConverterInterface; |
8
|
|
|
use Leonidas\Contracts\System\Schema\Post\QueryFactoryInterface; |
9
|
|
|
use Leonidas\Contracts\System\Schema\Term\TermConverterInterface; |
10
|
|
|
use Leonidas\Contracts\System\Schema\User\UserConverterInterface; |
11
|
|
|
use Nette\PhpGenerator\PhpNamespace; |
12
|
|
|
use WP_Comment_Query; |
|
|
|
|
13
|
|
|
use WP_Query; |
|
|
|
|
14
|
|
|
use WP_Term_Query; |
|
|
|
|
15
|
|
|
use WP_User_Query; |
|
|
|
|
16
|
|
|
|
17
|
|
|
class ModelQueryFactoryPrinter extends AbstractClassPrinter |
18
|
|
|
{ |
19
|
|
|
public const QUERIES = [ |
20
|
|
|
'post' => WP_Query::class, |
21
|
|
|
'post:h' => WP_Query::class, |
22
|
|
|
'attachment' => WP_Query::class, |
23
|
|
|
// 'term' => WP_Term_Query::class, |
24
|
|
|
// 'term:h' => WP_Term_Query::class, |
25
|
|
|
// 'user' => WP_User_Query::class, |
26
|
|
|
// 'comment' => WP_Comment_Query::class, |
27
|
|
|
]; |
28
|
|
|
|
29
|
|
|
public const CONVERTERS = [ |
30
|
|
|
'post' => PostConverterInterface::class, |
31
|
|
|
'post:h' => PostConverterInterface::class, |
32
|
|
|
'attachment' => PostConverterInterface::class, |
33
|
|
|
// 'term' => TermConverterInterface::class, |
34
|
|
|
// 'term:h' => TermConverterInterface::class, |
35
|
|
|
// 'user' => UserConverterInterface::class, |
36
|
|
|
// 'comment' => CommentConverterInterface::class, |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
protected string $query; |
40
|
|
|
|
41
|
|
|
protected string $template; |
42
|
|
|
|
43
|
|
|
public function __construct(string $namespace, string $class, string $query, string $template) |
44
|
|
|
{ |
45
|
|
|
parent::__construct($namespace, $class); |
46
|
|
|
$this->query = $query; |
47
|
|
|
$this->template = $template; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function setupClass(PhpNamespace $namespace): object |
51
|
|
|
{ |
52
|
|
|
$base = QueryFactoryInterface::class; |
53
|
|
|
$query = static::QUERIES[$this->template]; |
54
|
|
|
$converter = static::CONVERTERS[$this->template]; |
55
|
|
|
$return = explode('\\', $this->query); |
56
|
|
|
$return = end($return); |
57
|
|
|
|
58
|
|
|
$class = $namespace |
59
|
|
|
->addUse($base) |
60
|
|
|
->addUse($converter) |
61
|
|
|
->addUse($query) |
62
|
|
|
->addClass($this->class); |
63
|
|
|
|
64
|
|
|
$class->addImplement($base); |
65
|
|
|
|
66
|
|
|
$class->addMethod('__construct') |
67
|
|
|
->setPublic() |
68
|
|
|
->addBody('$this->converter = $converter;') |
69
|
|
|
->addParameter('converter') |
70
|
|
|
->setType($converter); |
71
|
|
|
|
72
|
|
|
$class->addMethod('createQuery') |
73
|
|
|
->setPublic() |
74
|
|
|
->addBody(sprintf('return new %s($query, $this->converter);', $return)) |
75
|
|
|
->setReturnType($this->query) |
76
|
|
|
->addParameter('query') |
77
|
|
|
->setType($query); |
78
|
|
|
|
79
|
|
|
return $class; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths