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

JBZoo / CI-Report-Converter / 6792564816

14 Oct 2023 08:18PM UTC coverage: 94.375%. Remained the same
6792564816

push

github

web-flow
PHP CS Fixer - `ordered_types` (#40)

1426 of 1511 relevant lines covered (94.37%)

28.38 hits per line

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

75.76
/src/Formats/Metric/Metrics.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - CI-Report-Converter.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/CI-Report-Converter
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\CIReportConverter\Formats\Metric;
18

19
use JBZoo\CIReportConverter\Formats\AbstractNode;
20
use JBZoo\CIReportConverter\Formats\MetricMaps\AbstractMetricMap;
21

22
final class Metrics extends AbstractNode
23
{
24
    private array $metrics = [];
25

26
    private ?AbstractMetricMap $map = null;
27

28
    public function add(string $key, null|float|int $value = null): self
29
    {
30
        $key = \trim($key);
24✔
31
        if ($key === '') {
24✔
32
            return $this;
×
33
        }
34

35
        if (!\array_key_exists($key, $this->metrics)) {
24✔
36
            $this->metrics[$key] = $value;
24✔
37
        }
38

39
        return $this;
24✔
40
    }
41

42
    public function setMap(AbstractMetricMap $map): self
43
    {
44
        $this->map = $map;
24✔
45

46
        return $this;
24✔
47
    }
48

49
    public function toArray(): array
50
    {
51
        $metrics = $this->getMetrics();
×
52

53
        $result = [];
×
54

55
        foreach ($metrics as $metric) {
×
56
            if ($metric->name !== '') {
×
57
                $result[$metric->name] = $metric->toArray();
×
58
            }
59
        }
60

61
        return $result;
×
62
    }
63

64
    /**
65
     * @return Metric[]
66
     */
67
    public function getMetrics(): array
68
    {
69
        $columnMap = [];
24✔
70
        $toolName  = '';
24✔
71

72
        if ($this->map !== null) {
24✔
73
            $columnMap = $this->map->getMap();
24✔
74
            $toolName  = $this->map->getName() . ':';
24✔
75
        }
76

77
        $result = [];
24✔
78

79
        foreach ($this->metrics as $key => $value) {
24✔
80
            if ($value === null) {
24✔
81
                continue;
×
82
            }
83

84
            $key = (string)$key;
24✔
85

86
            $metric        = new Metric();
24✔
87
            $metric->key   = $key;
24✔
88
            $metric->value = $value;
24✔
89
            $metric->name  = \array_key_exists($key, $columnMap)
24✔
90
                ? "{$columnMap[$key]} ({$toolName}{$key})"
24✔
91
                : "{$toolName}{$key}";
8✔
92

93
            $result[$key] = $metric;
24✔
94
        }
95

96
        \uasort($result, static fn (Metric $metric1, Metric $metric2): int => \strcmp($metric1->name, $metric2->name));
24✔
97

98
        return $result;
24✔
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

© 2025 Coveralls, Inc