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

timber / timber / 5690057835

pending completion
5690057835

push

github

nlemoine
Merge branch '2.x' of github.com:timber/timber into 2.x-refactor-file-models

# Conflicts:
#	src/Attachment.php
#	src/ExternalImage.php
#	src/FileSize.php
#	src/URLHelper.php

1134 of 1134 new or added lines in 55 files covered. (100.0%)

3923 of 4430 relevant lines covered (88.56%)

59.08 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

© 2025 Coveralls, Inc