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

conedevelopment / root / 13086943877

01 Feb 2025 08:35AM UTC coverage: 79.285% (+1.2%) from 78.037%
13086943877

push

github

web-flow
Merge pull request #234 from xHeaven/patch-1

Codebase health checkup

195 of 239 new or added lines in 45 files covered. (81.59%)

2 existing lines in 2 files now uncovered.

2572 of 3244 relevant lines covered (79.28%)

35.8 hits per line

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

16.13
/src/Widgets/Value.php
1
<?php
2

3
namespace Cone\Root\Widgets;
4

5
use DatePeriod;
6
use Illuminate\Database\Eloquent\Builder;
7

8
abstract class Value extends Metric
9
{
10
    /**
11
     * The Blade template.
12
     */
13
    protected string $template = 'root::widgets.value';
14

15
    /**
16
     * The widget icon.
17
     */
18
    protected ?string $icon = null;
19

20
    /**
21
     * Create a new widget instance.
22
     */
23
    public function __construct()
24
    {
25
        parent::__construct();
198✔
26

27
        $this->class('app-widget--summary');
198✔
28
    }
29

30
    /**
31
     * Set the icon.
32
     */
33
    public function icon(string $value): static
34
    {
35
        $this->icon = $value;
×
36

37
        return $this;
×
38
    }
39

40
    /**
41
     * Apply the aggregate function on the query.
42
     */
43
    protected function aggregate(Builder $query, DatePeriod $period, string $fn, string $column, ?string $dateColumn = null): Builder
44
    {
45
        $dateColumn ??= $query->getModel()->getQualifiedCreatedAtColumn();
×
46

47
        $extended = $this->period(
×
48
            $period->getStartDate()->sub($period->getEndDate()->diff($period->getStartDate(), true))->format('c'),
×
49
            $period->getEndDate()->format('c')
×
50
        );
×
51

52
        return parent::aggregate($query, $extended, $fn, $column, $dateColumn)->when(
×
53
            $period->getStartDate()->getTimestamp() > 0,
×
NEW
54
            fn (Builder $query): Builder => $query->selectRaw(sprintf(
×
NEW
55
                "(case when %s between '%s' and '%s' then 'current' else 'previous' end) as `__interval`",
×
NEW
56
                $query->getQuery()->getGrammar()->wrap($dateColumn),
×
NEW
57
                $period->getStartDate()->format('Y-m-d H:i:s'),
×
NEW
58
                $period->getEndDate()->format('Y-m-d H:i:s')
×
NEW
59
            ))->groupBy('__interval')
×
UNCOV
60
        );
×
61
    }
62

63
    /**
64
     * Get the query result.
65
     */
66
    public function result(Builder $query): array
67
    {
68
        $result = array_merge(['current' => 0, 'previous' => 0], parent::result($query));
×
69

70
        return [
×
71
            'current' => round($result['current'], 2),
×
72
            'previous' => round($result['previous'], 2),
×
73
            'trend' => $this->trend($result),
×
74
        ];
×
75
    }
76

77
    /**
78
     * Calculate the trend value.
79
     */
80
    protected function trend(array $result): float
81
    {
82
        $divider = ($result['current'] + $result['previous']);
×
83

84
        if ($result['previous'] == 0 || $divider == 0) {
×
85
            return 0;
×
86
        }
87

88
        return round(($result['current'] - $result['previous']) / ($divider / 2) * 100, 1);
×
89
    }
90

91
    /**
92
     * Convert the widget to an array.
93
     */
94
    public function toArray(): array
95
    {
96
        return array_merge(parent::toArray(), [
3✔
97
            'icon' => $this->icon,
3✔
98
        ]);
3✔
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