Completed
Push — master ( 0e8d6a...d4610b )
by Jakub
02:58
created

RssExtension::getConfigSchema()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Nexendrie\Rss\Bridges\NetteDI;
5
6
use Nette\DI\CompilerExtension;
7
use Nexendrie\Rss\Generator;
8
use Nette\Schema\Expect;
9
10
/**
11
 * RssExtension for Nette DI Container
12
 *
13
 * @author Jakub Konečný
14
 */
15 1
final class RssExtension extends CompilerExtension {
16
  protected function setProperty(\Nette\DI\ServiceDefinition &$generator, \stdClass $config, string $property): void {
17 1
    if($config->$property !== "") {
18 1
      $generator->addSetup('$service->' . $property . " = ?", [$config->$property]);
19
    }
20 1
  }
21
22
  public function getConfigSchema(): \Nette\Schema\Schema {
23 1
    return Expect::structure([
24 1
      "shortenDescription" => Expect::int(150),
25 1
      "dateTimeFormat" => Expect::string(""),
26 1
      "template" => Expect::string(""),
27
    ]);
28
  }
29
30
  /**
31
   * @throws \Nette\Utils\AssertionException
32
   */
33
  public function loadConfiguration(): void {
34
    /** @var \stdClass $config */
35 1
    $config = $this->getConfig();
36 1
    $builder = $this->getContainerBuilder();
37 1
    $generator = $builder->addDefinition($this->prefix("generator"))
38 1
      ->setType(Generator::class)
39 1
      ->addSetup('$service->shortenDescription = ?', [$config->shortenDescription]);
40 1
    $this->setProperty($generator, $config, "dateTimeFormat");
41 1
    $this->setProperty($generator, $config, "template");
42 1
  }
43
}
44
?>