|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Leonidas\Library\System\Schema\Post; |
|
4
|
|
|
|
|
5
|
|
|
use Countable; |
|
6
|
|
|
use Iterator; |
|
7
|
|
|
use Leonidas\Contracts\System\Schema\Post\PostConversionArchiveInterface; |
|
8
|
|
|
use Leonidas\Contracts\System\Schema\Post\PostConverterInterface; |
|
9
|
|
|
use Leonidas\Library\System\Schema\Post\Abstracts\ManagesPostConversionsTrait; |
|
10
|
|
|
use WP_Query; |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class PostQueryIterator implements Iterator, Countable |
|
13
|
|
|
{ |
|
14
|
|
|
use ManagesPostConversionsTrait; |
|
15
|
|
|
|
|
16
|
|
|
protected WP_Query $query; |
|
17
|
|
|
|
|
18
|
|
|
public function __construct( |
|
19
|
|
|
WP_Query $query, |
|
20
|
|
|
PostConverterInterface $converter, |
|
21
|
|
|
?PostConversionArchiveInterface $archive = null |
|
22
|
|
|
) { |
|
23
|
|
|
$this->query = $query; |
|
24
|
|
|
$this->converter = $converter; |
|
25
|
|
|
$this->conversionArchive = $archive; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function current(): object |
|
29
|
|
|
{ |
|
30
|
|
|
$this->maybeStartLoop(); |
|
31
|
|
|
|
|
32
|
|
|
return $this->getConvertedPost($GLOBALS['post']); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function key(): int |
|
36
|
|
|
{ |
|
37
|
|
|
return $this->query->current_post; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function next(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$this->maybeStartLoop(); |
|
43
|
|
|
|
|
44
|
|
|
if (!$this->loopEnded()) { |
|
45
|
|
|
$this->nextPost(); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function rewind(): void |
|
50
|
|
|
{ |
|
51
|
|
|
$this->query->rewind_posts(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function valid(): bool |
|
55
|
|
|
{ |
|
56
|
|
|
if (!$valid = $this->query->have_posts()) { |
|
57
|
|
|
$this->resetData(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
return $valid; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function count(): int |
|
64
|
|
|
{ |
|
65
|
|
|
return count($this->query->posts); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
protected function maybeStartLoop(): void |
|
69
|
|
|
{ |
|
70
|
|
|
if (!$this->loopStarted()) { |
|
71
|
|
|
$this->nextPost(); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
protected function loopStarted(): bool |
|
76
|
|
|
{ |
|
77
|
|
|
return $this->key() > -1; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
protected function loopEnded(): bool |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->key() === $this->count() - 1; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
protected function nextPost(): void |
|
86
|
|
|
{ |
|
87
|
|
|
$this->query->the_post(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
protected function resetData(): void |
|
91
|
|
|
{ |
|
92
|
|
|
wp_reset_postdata(); |
|
|
|
|
|
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
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