• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

timber / timber / 5690593717

pending completion
5690593717

Pull #1617

github

web-flow
Merge f587ceffa into b563d274e
Pull Request #1617: 2.x

4433 of 4433 new or added lines in 57 files covered. (100.0%)

3931 of 4433 relevant lines covered (88.68%)

58.28 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

23.08
/src/PostArrayObject.php
1
<?php
2

3
namespace Timber;
4

5
use ArrayObject;
6
use JsonSerializable;
7
use ReturnTypeWillChange;
8
use WP_Post;
9

10
/**
11
 * PostArrayObject class for dealing with arbitrary collections of Posts
12
 * (typically not wrapping a `WP_Query` directly, which is what `Timber\PostQuery` does).
13
 *
14
 * @api
15
 */
16
class PostArrayObject extends ArrayObject implements PostCollectionInterface, JsonSerializable
17
{
18
    use AccessesPostsLazily;
19

20
    /**
21
     * Takes an arbitrary array of WP_Posts to wrap and (lazily) translate to
22
     * Timber\Post instances.
23
     *
24
     * @api
25
     * @param WP_Post[] $posts an array of WP_Post objects
26
     */
27
    public function __construct(array $posts)
28
    {
29
        parent::__construct($posts, 0, PostsIterator::class);
31✔
30
    }
31

32
    /**
33
     * @inheritdoc
34
     */
35
    public function pagination(array $options = [])
36
    {
37
        return null;
2✔
38
    }
39

40
    /**
41
     * Override data printed by var_dump() and similar. Realizes the collection before
42
     * returning. Due to a PHP bug, this only works in PHP >= 7.4.
43
     *
44
     * @see https://bugs.php.net/bug.php?id=69264
45
     * @internal
46
     */
47
    public function __debugInfo(): array
48
    {
49
        return [
×
50
            'info' => \sprintf(
×
51
                '
×
52
********************************************************************************
53

54
    This output is generated by %s().
55

56
    The properties you see here are not actual properties, but only debug
57
    output. If you want to access the actual instances of Timber\Posts, loop
58
        over the collection or get all posts through $query->to_array().
59

60
        More info: https://timber.github.io/docs/v2/guides/posts/#debugging-post-collections
61

62
********************************************************************************',
×
63
                __METHOD__
×
64
            ),
×
65
            'posts' => $this->getArrayCopy(),
×
66
            'factory' => $this->factory,
×
67
            'iterator' => $this->getIterator(),
×
68
        ];
×
69
    }
70

71
    /**
72
     * Returns realized (eagerly instantiated) Timber\Post data to serialize to JSON.
73
     *
74
     * @internal
75
     */
76
    #[ReturnTypeWillChange]
77
    public function jsonSerialize()
78
    {
79
        return $this->getArrayCopy();
2✔
80
    }
81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc