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

The-oGlow / ezkoding / 37223656461

04 Oct 2026 06:14PM UTC coverage: 84.414% (-0.6%) from 85.037%
37223656461

push

github

ollily
#1 update / tested

11 of 13 new or added lines in 4 files covered. (84.62%)

5 existing lines in 1 file now uncovered.

677 of 802 relevant lines covered (84.41%)

7.23 hits per line

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

82.5
/src/Tools/Batch/BatchTaskHelper.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of ezkoding
7
 *
8
 * (c) 2025 Oliver Glowa, coding.glowa.com
9
 *
10
 * This source file is subject to the Apache-2.0 license that is bundled
11
 * with this source code in the file LICENSE.
12
 */
13

14
namespace ollily\Tools\Batch;
15

16
use Ds\Map;
17
use Monolog\EasyGoingLogger;
18
use Psr\Log\LoggerInterface;
19

20
/**
21
 * @phpstan-import-type TTaskListId from ITaskList
22
 * @phpstan-import-type TTaskItemId from ITaskItem
23
 */
24
class BatchTaskHelper
25
{
26
    /** Default key for a tasklist. */
27
    public const string DEFAULT = 'DEFAULT';
28

29
    public const bool DEFAULT_WITH_DATA_KEYS = TaskList::DEFAULT_WITH_DATA_ITEM_ID;
30

31
    public const int COL_PAGEID = 0;
32

33
    public const int COL_TITLE = 1;
34

35
    private static bool $isInit = false;
36

37
    /** @var Map<mixed,TaskList>
38
     * @phpstan-var Map<TTaskListId,TaskList> */
39
    protected static Map $tasklists;
40

41
    protected static LoggerInterface $logger;
42

43
    protected static IBatchConfig $defaultConfig;
44

45
    private function __construct()
×
46
    {
47
        self::init();
×
48
    }
49

50
    /**
51
     * @psalm-suppress RedundantPropertyInitializationCheck
52
     */
53
    public static function init(): void
1 ✔
54
    {
55
        if (!self::$isInit) {
1 ✔
56
            if (!isset(self::$logger)) {
1 ✔
57
                self::$logger = EasyGoingLogger::init(BatchTaskHelper::class);
1 ✔
58
            }
59
            if (!isset(self::$tasklists)) {
1 ✔
60
                self::$tasklists = new Map();
1 ✔
61
            }
62
            if (!isset(self::$defaultConfig)) {
1 ✔
63
                self::$defaultConfig = new BatchConfig(new Map());
1 ✔
64
            }
65
            self::$isInit = true;
1 ✔
66
        }
67
    }
68

69
    /**
70
     * @return LoggerInterface
71
     */
72
    private static function logger(): LoggerInterface
1 ✔
73
    {
74
        self::init();
1 ✔
75

76
        return self::$logger;
1 ✔
77
    }
78

79
    /**
80
     * @return Map<mixed,TaskList>
81
     *
82
     * @phpstan-return Map<TTaskListId,TaskList>
83
     */
84
    private static function taskLists(): Map
1 ✔
85
    {
86
        self::init();
1 ✔
87

88
        return self::$tasklists;
1 ✔
89
    }
90

91
    /**
92
     * @return IBatchConfig
93
     */
UNCOV
94
    private static function defaultConfig(): IBatchConfig
×
95
    {
UNCOV
96
        self::init();
×
97

UNCOV
98
        return self::$defaultConfig;
×
99
    }
100

101
    /**
102
     * @param mixed         $listId
103
     * @param ?IBatchConfig $listConfig
104
     * @param bool          $withHeader TRUE=with heade columns, else FALSE (only used, if tasklist will be newly created)
105
     *
106
     * @phpstan-param $listId TTaskListId
107
     *
108
     * @return TaskList
109
     */
110
    public static function getTaskList(
1 ✔
111
        mixed $listId = self::DEFAULT,
112
        ?IBatchConfig $listConfig = null,
113
        bool $withHeader = self::DEFAULT_WITH_DATA_KEYS
114
    ): TaskList {
115
        self::init();
1 ✔
116
        self::logger()->debug('START - listId', [$listId]);
1 ✔
117

118
        $listId = empty($listId) ? self::DEFAULT : $listId;
1 ✔
119
        $listConfig = empty($listConfig) ? self::defaultConfig() : $listConfig;
1 ✔
120
        if (!self::taskLists()->hasKey($listId)) {
1 ✔
121
            self::taskLists()->put($listId, new TaskList($listId, $listConfig, $withHeader));
1 ✔
122
        }
123

124
        self::logger()->debug('END');
1 ✔
125

126
        return self::taskLists()->get($listId);
1 ✔
127
    }
128

129
    /**
130
     * @param string        $fileName
131
     * @param ?IBatchConfig $listConfig
132
     * @param mixed         $listId
133
     * @param bool          $withHeader TRUE=with heade columns, else FALSE
134
     *
135
     * @phpstan-param TTaskListId $listId
136
     *
137
     * @return TaskList
138
     */
139
    public static function readTaskList(
1 ✔
140
        string $fileName,
141
        ?IBatchConfig $listConfig = null,
142
        mixed $listId = self::DEFAULT,
143
        bool $withHeader = self::DEFAULT_WITH_DATA_KEYS
144
    ): TaskList {
145
        self::init();
1 ✔
146
        self::logger()->debug('START - listKey,fileName', [$listId, $fileName]);
1 ✔
147

148
        $listId = empty($listId) ? self::DEFAULT : $listId;
1 ✔
149
        if (file_exists($fileName)) {
1 ✔
UNCOV
150
            $taskList = self::getTaskList($listId, $listConfig, $withHeader);
×
UNCOV
151
            $taskList->readFile($fileName);
×
152
        } else {
153
            self::logger()->warning('File does not exists', [$fileName]);
1 ✔
154
            $taskList = self::getTaskList($listId, $listConfig, $withHeader);
1 ✔
155
        }
156

157
        self::logger()->debug('END');
1 ✔
158

159
        return $taskList;
1 ✔
160
    }
161
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc