Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Seo | |
100.00% |
10 / 10 |
|
100.00% |
6 / 6 |
10 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| create | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| update | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| delete | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMetaRobots | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * All SEO relevant stuff. |
| 5 | * |
| 6 | * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 7 | * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 8 | * obtain one at https://mozilla.org/MPL/2.0/. |
| 9 | * |
| 10 | * @package phpMyFAQ |
| 11 | * @author Thorsten Rinne <thorsten@phpmyfaq.de> |
| 12 | * @author Gustavo Solt <gustavo.solt@mayflower.de> |
| 13 | * @copyright 2014-2026 phpMyFAQ Team |
| 14 | * @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0 |
| 15 | * @link https://www.phpmyfaq.de |
| 16 | * @since 2014-08-31 |
| 17 | */ |
| 18 | |
| 19 | declare(strict_types=1); |
| 20 | |
| 21 | namespace phpMyFAQ; |
| 22 | |
| 23 | use Exception; |
| 24 | use phpMyFAQ\Entity\SeoEntity; |
| 25 | use phpMyFAQ\Seo\SeoRepository; |
| 26 | use phpMyFAQ\Seo\SeoRepositoryInterface; |
| 27 | |
| 28 | /** |
| 29 | * Class Seo |
| 30 | * |
| 31 | * @package phpMyFAQ |
| 32 | */ |
| 33 | readonly class Seo |
| 34 | { |
| 35 | private SeoRepositoryInterface $seoRepository; |
| 36 | |
| 37 | public function __construct( |
| 38 | private Configuration $configuration, |
| 39 | ?SeoRepositoryInterface $seoRepository = null, |
| 40 | ) { |
| 41 | $this->seoRepository = $seoRepository ?? new SeoRepository($this->configuration); |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * @return bool True if the SEO entity was created |
| 46 | */ |
| 47 | public function create(SeoEntity $seoEntity): bool |
| 48 | { |
| 49 | return $this->seoRepository->create($seoEntity); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * @throws Exception |
| 54 | */ |
| 55 | public function get(SeoEntity $seoEntity): SeoEntity |
| 56 | { |
| 57 | return $this->seoRepository->get($seoEntity); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @return bool True if the SEO entity was updated |
| 62 | */ |
| 63 | public function update(SeoEntity $seoEntity): bool |
| 64 | { |
| 65 | return $this->seoRepository->update($seoEntity); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * @return bool True if the SEO entity was deleted |
| 70 | */ |
| 71 | public function delete(SeoEntity $seoEntity): bool |
| 72 | { |
| 73 | return $this->seoRepository->delete($seoEntity); |
| 74 | } |
| 75 | |
| 76 | public function getMetaRobots(string $action): string |
| 77 | { |
| 78 | return (string) match ($action) { |
| 79 | 'main' => $this->configuration->get(item: 'seo.metaTagsHome'), |
| 80 | 'faq' => $this->configuration->get(item: 'seo.metaTagsFaqs'), |
| 81 | 'show' => $this->configuration->get(item: 'seo.metaTagsCategories'), |
| 82 | default => $this->configuration->get(item: 'seo.metaTagsPages'), |
| 83 | }; |
| 84 | } |
| 85 | } |