Passed
Push — 6.0 ( 7ab78c...8e0f01 )
by Olivier
01:35
created

lib/ActiveRecord/ScopeNotDefined.php (2 issues)

1
<?php
2
3
/*
4
 * This file is part of the ICanBoogie package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ICanBoogie\ActiveRecord;
13
14
use ICanBoogie\Accessor\AccessorTrait;
15
use LogicException;
16
use Throwable;
17
18
/**
19
 * Exception thrown in attempt to obtain a scope that is not defined.
20
 *
21
 * @property-read string $scope_name
22
 * @property-read Model $model
23
 */
24
class ScopeNotDefined extends LogicException implements Exception
25
{
26
    /**
27
     * @uses get_scope_name
28
     * @uses get_model
29
     */
30
    use AccessorTrait;
31
32
    private function get_scope_name(): string
0 ignored issues
show
The method get_scope_name() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
33
    {
34
        return $this->scope_name;
35
    }
36
37
    private function get_model(): Model
0 ignored issues
show
The method get_model() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
38
    {
39
        return $this->model;
40
    }
41
42
    public function __construct(
43
        private string $scope_name,
44
        private Model $model,
45
        Throwable $previous = null
46
    ) {
47
        parent::__construct($this->format_message($scope_name, $model), 0, $previous);
48
    }
49
50
    private function format_message(string $scope_name, Model $model): string
51
    {
52
        return "Unknown scope `$scope_name` for model `$model->unprefixed_name`.";
53
    }
54
}
55