Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
OlzRootComponent
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 4
42
0.00% covered (danger)
0.00%
0 / 1
 hasAccess
n/a
0 / 0
n/a
0 / 0
0
 searchSql
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 searchSqlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getHtml
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getHtmlWhenHasAccess
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Olz\Components\Common;
4
5use Olz\Suche\Utils\SearchUtils;
6
7/**
8 * @phpstan-type WithQuery array{with: array<string>, query: string}
9 *
10 * @phpstan-import-type SearchResult from SearchUtils
11 *
12 * @template T
13 *
14 * @extends OlzComponent<T>
15 */
16abstract class OlzRootComponent extends OlzComponent {
17    abstract public function hasAccess(): bool;
18
19    /**
20     * @param array<string> $terms
21     *
22     * @return string|WithQuery|null
23     */
24    public function searchSql(array $terms): string|array|null {
25        if (!$this->hasAccess()) {
26            return null;
27        }
28        return $this->searchSqlWhenHasAccess($terms);
29    }
30
31    /**
32     * @param array<string> $terms
33     *
34     * @return string|WithQuery|null
35     */
36    public function searchSqlWhenHasAccess(array $terms): string|array|null {
37        $called_class = get_called_class();
38        throw new \Exception("{$called_class}::searchSqlWhenHasAccess is not implemented");
39    }
40
41    /** @param T $args */
42    public function getHtml(mixed $args): string {
43        if (!$this->hasAccess()) {
44            $this->httpUtils()->dieWithHttpError(403);
45        }
46        return $this->getHtmlWhenHasAccess($args);
47    }
48
49    /** @param T $args */
50    public function getHtmlWhenHasAccess(mixed $args): string {
51        $called_class = get_called_class();
52        throw new \Exception("{$called_class}::getHtmlWhenHasAccess is not implemented");
53    }
54}