• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

vysokeskoly / SolrFeeder / 26080989351

19 May 2026 06:44AM UTC coverage: 40.436% (+0.05%) from 40.389%
26080989351

Pull #9

github

web-flow
Merge d70b3d093 into c5043a7cd
Pull Request #9: Allow paths to the absolute and add dockerfile for k8s

1 of 2 new or added lines in 1 file covered. (50.0%)

167 of 413 relevant lines covered (40.44%)

1.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

38.71
/src/Entity/Timestamps.php
1
<?php declare(strict_types=1);
2

3
namespace VysokeSkoly\SolrFeeder\Entity;
4

5
use MF\Collection\Immutable\Generic\IMap;
6
use MF\Collection\Immutable\Generic\Map;
7
use VysokeSkoly\SolrFeeder\Service\XmlParser;
8
use VysokeSkoly\SolrFeeder\ValueObject\PrimaryKey;
9

10
class Timestamps
11
{
12
    private bool $lastValuesLoaded = false;
13
    /** @phpstan-var IMap<string, string> */
14
    private IMap $current;
15

16
    /** @phpstan-param IMap<string, Timestamp> $timestampMap */
17
    public function __construct(
18
        private readonly string $filePath,
19
        private readonly IMap $timestampMap,
20
        private readonly XmlParser $xmlParser,
21
    ) {
22
        $this->current = new Map();
3✔
23
    }
24

25
    /** @phpstan-return IMap<string, Timestamp> */
26
    public function getTimestampMap(): IMap
27
    {
28
        $this->loadLastValuesFromFile();
2✔
29

30
        return $this->timestampMap;
2✔
31
    }
32

33
    private function loadLastValuesFromFile(): void
34
    {
35
        $filename = $this->getFileFullPath();
2✔
36
        if (!$this->lastValuesLoaded && file_exists($filename)) {
2✔
37
            $this->xmlParser->parseTimestampsFile($filename)
1✔
38
                ->each(function (string $value, string $type = ''): void {
1✔
39
                    /** @var Timestamp $timestamp */
40
                    $timestamp = $this->timestampMap->get($type);
1✔
41

42
                    $timestamp->setLastValue($value);
1✔
43
                });
44
            $this->lastValuesLoaded = true;
1✔
45
        }
46
    }
47

48
    public function saveValuesToFile(): void
49
    {
50
        $fileName = $this->getFileFullPath();
×
51
        $dirName = dirname($fileName);
×
52

53
        $xml = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8" standalone="yes"?><timestamps/>');
×
54
        $xml->addAttribute('updatedOn', (new \DateTime())->format('Y-m-d H:i:s.vP'));
×
55

56
        $xml = $this->getTimestampMap()->reduce(
×
57
            function (\SimpleXMLElement $xml, Timestamp $timestamp) {
×
58
                $xml
59
                    ->addChild('timestamp', $timestamp->getCurrentUpdated())
×
60
                    ->addAttribute('name', $timestamp->getType());
×
61

62
                return $xml;
×
63
            },
64
            $xml,
65
        );
66

67
        if (!file_exists($dirName)) {
×
68
            if (!mkdir($dirName, 0777, true) && !is_dir($dirName)) {
×
69
                throw new \RuntimeException(sprintf('Directory "%s" was not created', $dirName));
×
70
            }
71
        }
72

73
        $xml->saveXML($fileName);
×
74
    }
75

76
    private function getFileFullPath(): string
77
    {
78
        // Support absolute paths (e.g. a mounted PVC at /var/solr-feeder/...)
79
        // as well as legacy relative paths (resolved from the app root).
80
        if (str_starts_with($this->filePath, '/')) {
2✔
NEW
81
            return $this->filePath;
×
82
        }
83

84
        return __DIR__ . '/../../' . $this->filePath;
2✔
85
    }
86

87
    public function setCurrent(PrimaryKey $primaryKey, string $currentTimestamp): void
88
    {
89
        $this->current = $this->current->set($primaryKey->getValue(), $currentTimestamp);
×
90
    }
91

92
    public function getCurrentTimestamp(PrimaryKey $primaryKey): ?string
93
    {
94
        $primaryKeyValue = $primaryKey->getValue();
×
95

96
        return $this->current->containsKey($primaryKeyValue)
×
97
            ? $this->current->get($primaryKeyValue)
×
98
            : null;
×
99
    }
100
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc