| Total Complexity | 8 |
| Total Lines | 49 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 1 | Features | 0 |
| 1 | <?php |
||
| 9 | class SettingsService |
||
| 10 | { |
||
| 11 | /** @var Settings */ |
||
| 12 | private $settings; |
||
| 13 | |||
| 14 | public function __construct(SettingsRepository $settingsRepository, EntityManagerInterface $entityManager) |
||
| 15 | { |
||
| 16 | $settings = $settingsRepository->getTheSingleRow(); |
||
| 17 | if ($settings === null) { |
||
| 18 | // Minuscule chance of a race condition but in that worst-case scenario |
||
| 19 | // we'll always bring back the first row from the database when we |
||
| 20 | // getTheSingleRow() so all that will happen is that an extra row |
||
| 21 | // will languish in the database forever. |
||
| 22 | $settings = new Settings(); |
||
| 23 | $entityManager->persist($settings); |
||
| 24 | $entityManager->flush(); |
||
| 25 | } |
||
| 26 | $this->settings = $settings; |
||
| 27 | } |
||
| 28 | |||
| 29 | public function getSettings(): Settings |
||
| 30 | { |
||
| 31 | return $this->settings; |
||
| 32 | } |
||
| 33 | |||
| 34 | // Helpers for Twig |
||
| 35 | public function getSiteTitle() : string |
||
| 36 | { |
||
| 37 | return $this->settings->getSiteTitle() ?? ""; |
||
| 38 | } |
||
| 39 | |||
| 40 | public function getSiteSubtitle() : string |
||
| 41 | { |
||
| 42 | return $this->settings->getSiteSubtitle() ?? ""; |
||
| 43 | } |
||
| 44 | |||
| 45 | public function getSiteAbout() : string |
||
| 48 | } |
||
| 49 | |||
| 50 | public function displayTwitterCards(): bool |
||
| 51 | { |
||
| 52 | return !empty($this->settings->getTwitterHandle()); |
||
| 53 | } |
||
| 54 | |||
| 55 | public function getTwitterHandle(): string |
||
| 58 | } |
||
| 59 | } |