Debian Codegraph @

vendor/ramsey/collection/src/Set.php

raw
1 <?php
2
3 /**
4 * This file is part of the ramsey/collection library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <[email protected]>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12
13 declare(strict_types=1);
14
15 namespace Ramsey\Collection;
16
17 /**
18 * A set is a collection that contains no duplicate elements.
19 *
20 * Great care must be exercised if mutable objects are used as set elements.
21 * The behavior of a set is not specified if the value of an object is changed
22 * in a manner that affects equals comparisons while the object is an element in
23 * the set.
24 *
25 * Example usage:
26 *
27 * ```
28 * $foo = new \My\Foo();
29 * $set = new Set(\My\Foo::class);
30 *
31 * $set->add($foo); // returns TRUE, the element doesn't exist
32 * $set->add($foo); // returns FALSE, the element already exists
33 *
34 * $bar = new \My\Foo();
35 * $set->add($bar); // returns TRUE, $bar !== $foo
36 * ```
37 *
38 * @template T
39 * @extends AbstractSet<T>
40 */
41 class Set extends AbstractSet
42 {
43 /**
44 * Constructs a set object of the specified type, optionally with the
45 * specified data.
46 *
47 * @param string $setType The type or class name associated with this set.
48 * @param array<array-key, T> $data The initial items to store in the set.
49 */
50 public function __construct(private readonly string $setType, array $data = [])
51 {
52 parent::__construct($data);
53 }
54
55 public function getType(): string
56 {
57 return $this->setType;
58 }
59 }