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

chdemko / php-sorted-collections / 24611550585

18 Apr 2026 06:53PM UTC coverage: 99.355% (-0.5%) from 99.869%
24611550585

push

github

chdemko
🚨 Fix scrutinizer

28 of 32 new or added lines in 3 files covered. (87.5%)

770 of 775 relevant lines covered (99.35%)

114.09 hits per line

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

72.73
/src/SortedCollection/ReversedSet.php
1
<?php
2

3
/**
4
 * chdemko\SortedCollection\ReversedSet class
5
 *
6
 * @author    Christophe Demko <chdemko@gmail.com>
7
 * @copyright Copyright (C) 2012-2024 Christophe Demko. All rights reserved.
8
 *
9
 * @license BSD 3-Clause License
10
 *
11
 * This file is part of the php-sorted-collections package https://github.com/chdemko/php-sorted-collections
12
 */
13

14
// Declare chdemko\SortedCollection namespace
15
namespace chdemko\SortedCollection;
16

17
/**
18
 * Reversed set
19
 *
20
 * @package    SortedCollection
21
 * @subpackage Set
22
 *
23
 * @since 1.0.0
24
 *
25
 * @property-read callable   $comparator  The element comparison function
26
 * @property-read mixed      $first       The first element of the set
27
 * @property-read mixed      $last        The last element of the set
28
 * @property-read integer    $count       The number of elements in the set
29
 * @property-read SortedSet  $set         The underlying set
30
 */
31
class ReversedSet extends AbstractSet
32
{
33
    /**
34
     * @var SortedSet  Internal set
35
     *
36
     * @since 1.0.0
37
     */
38
    private $setInternal;
39

40
    /**
41
     * Constructor
42
     *
43
     * @param SortedSet $set Internal set
44
     *
45
     * @since 1.0.0
46
     */
47
    protected function __construct(SortedSet $set)
48
    {
49
        if ($set instanceof AbstractSet) {
7✔
50
            $map = $set->getMap();
7✔
51
        } else {
NEW
52
            $map = TreeMap::create($set->comparator());
×
53

NEW
54
            foreach ($set as $value) {
×
NEW
55
                $map[$value] = true;
×
56
            }
57
        }
58

59
        $this->setMap(ReversedMap::create($map))->setInternal = $set;
7✔
60
    }
61

62
    /**
63
     * Create
64
     *
65
     * @param SortedSet $set Internal set
66
     *
67
     * @return ReversedSet A new reversed set
68
     *
69
     * @since 1.0.0
70
     */
71
    public static function create(SortedSet $set)
72
    {
73
        return new static($set);
7✔
74
    }
75

76
    /**
77
     * Magic get method
78
     *
79
     * @param string $property The property
80
     *
81
     * @return mixed The value associated to the property
82
     *
83
     * @since 1.0.0
84
     */
85
    public function __get($property)
86
    {
87
        switch ($property) {
88
            case 'set':
1✔
89
                return $this->setInternal;
1✔
90
            default:
91
                return parent::__get($property);
1✔
92
        }
93
    }
94

95
    /**
96
     * Serialize the object
97
     *
98
     * @return array Array of values
99
     *
100
     * @since 1.0.0
101
     */
102
    public function jsonSerialize(): array
103
    {
104
        return array('ReversedSet' => $this->setInternal->jsonSerialize());
1✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc