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

RssExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 27
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setProperty() 0 3 2
A loadConfiguration() 0 9 1
A getConfigSchema() 0 5 1
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
?>