Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
63.64% covered (warning)
63.64%
7 / 11
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
MagicGetterSetterTrait
63.64% covered (warning)
63.64%
7 / 11
0.00% covered (danger)
0.00%
0 / 1
6.20
0.00% covered (danger)
0.00%
0 / 1
 __call
63.64% covered (warning)
63.64%
7 / 11
0.00% covered (danger)
0.00%
0 / 1
6.20
1<?php
2
3declare(strict_types=1);
4/**
5 * SPDX-FileCopyrightText: 2020-2024 LibreCode coop and contributors
6 * SPDX-License-Identifier: AGPL-3.0-or-later
7 */
8
9namespace OCA\Libresign\Helper;
10
11trait MagicGetterSetterTrait {
12    public function __call($name, $arguments) {
13        if (!preg_match('/^(?<type>get|set)(?<property>.+)/', (string)$name, $matches)) {
14            throw new \LogicException(sprintf('Cannot set non existing property %s->%s = %s.', $this::class, $name, var_export($arguments, true)));
15        }
16        $property = lcfirst($matches['property']);
17        if (!property_exists($this, $property)) {
18            $property = $matches['property'];
19            if (!property_exists($this, $property)) {
20                throw new \LogicException(sprintf('Cannot set non existing property %s->%s = %s.', $this::class, $name, var_export($arguments, true)));
21            }
22        }
23        if ($matches['type'] === 'get') {
24            return $this->$property;
25        }
26        $this->$property = $arguments[0] ?? null;
27        return $this;
28    }
29}