Debian Codegraph @

lib/3rdParty/composer/nesbot/carbon/src/Carbon/Traits/Mutability.php

raw symbols SCIP
1 <?php
2
3 declare(strict_types=1);
4
5 /**
6 * This file is part of the Carbon package.
7 *
8 * (c) Brian Nesbitt <[email protected]>
9 *
10 * For the full copyright and license information, please view the LICENSE
11 * file that was distributed with this source code.
12 */
13
14 namespace Carbon\Traits;
15
16 use Carbon\Carbon;
17 use Carbon\CarbonImmutable;
18
19 /**
20 * Trait Mutability.
21 *
22 * Utils to know if the current object is mutable or immutable and convert it.
23 */
24 trait Mutability
25 {
26 use Cast;
27
28 /**
29 * Returns true if the current class/instance is mutable.
30 */
31 public static function isMutable(): bool
32 {
33 return false;
34 }
35
36 /**
37 * Returns true if the current class/instance is immutable.
38 */
39 public static function isImmutable(): bool
40 {
41 return !static::isMutable();
42 }
43
44 /**
45 * Return a mutable copy of the instance.
46 */
47 public function toMutable(): Carbon
48 {
49 return $this->cast(Carbon::class);
50 }
51
52 /**
53 * Return an immutable copy of the instance.
54 */
55 public function toImmutable(): CarbonImmutable
56 {
57 // Immutable objects are fine as is (uncloned)
58 if ($this::class === CarbonImmutable::class) {
59 return $this;
60 }
61
62 return $this->cast(CarbonImmutable::class);
63 }
64 }