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

contributte / datagrid / 20509702934

25 Dec 2025 07:11PM UTC coverage: 48.072% (+0.04%) from 48.034%
20509702934

Pull #1231

github

web-flow
Merge 4ec93c1c6 into ad555bb1c
Pull Request #1231: Deprecated null as array offset in applyReplacements

4 of 5 new or added lines in 1 file covered. (80.0%)

1309 of 2723 relevant lines covered (48.07%)

0.48 hits per line

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

52.0
/src/Traits/TButtonRenderer.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\Traits;
4

5
use Contributte\Datagrid\Column\Renderer;
6
use Contributte\Datagrid\Exception\DatagridColumnRendererException;
7
use Contributte\Datagrid\Exception\DatagridException;
8
use Contributte\Datagrid\Row;
9

10
trait TButtonRenderer
11
{
12

13
        protected ?Renderer $renderer = null;
14

15
        protected array $replacements = [];
16

17
        /**
18
         * @throws DatagridColumnRendererException
19
         */
20
        public function useRenderer(?Row $row = null): mixed
1✔
21
        {
22
                $renderer = $this->getRenderer();
1✔
23

24
                $args = $row instanceof Row ? [$row->getItem()] : [];
1✔
25

26
                if ($renderer === null) {
1✔
27
                        throw new DatagridColumnRendererException();
1✔
28
                }
29

30
                if ($renderer->getConditionCallback() !== null) {
×
31
                        if (call_user_func_array($renderer->getConditionCallback(), $args) === false) {
×
32
                                throw new DatagridColumnRendererException();
×
33
                        }
34

35
                        return call_user_func_array($renderer->getCallback(), $args);
×
36
                }
37

38
                return call_user_func_array($renderer->getCallback(), $args);
×
39
        }
40

41
        /**
42
         * Set renderer callback and (it may be optional - the condition callback will decide)
43
         *
44
         * @return static
45
         * @throws DatagridException
46
         */
47
        public function setRenderer(
48
                callable $renderer,
49
                ?callable $conditionCallback = null
50
        ): self
51
        {
52
                if ($this->hasReplacements()) {
×
53
                        throw new DatagridException('Use either Column::setReplacement() or Column::setRenderer, not both.');
×
54
                }
55

56
                $this->renderer = new Renderer($renderer, $conditionCallback);
×
57

58
                return $this;
×
59
        }
60

61
        /**
62
         * @return static
63
         */
64
        public function setRendererOnCondition(
65
                callable $renderer,
66
                callable $conditionCallback
67
        ): self
68
        {
69
                return $this->setRenderer($renderer, $conditionCallback);
×
70
        }
71

72
        public function getRenderer(): ?Renderer
73
        {
74
                return $this->renderer;
1✔
75
        }
76

77
        public function hasReplacements(): bool
78
        {
79
                return $this->replacements !== [];
×
80
        }
81

82
        public function applyReplacements(Row $row, string $column): array
1✔
83
        {
84
                $value = $row->getValue($column);
1✔
85
                if (!is_scalar($value) && $value !== null) {
1✔
86
                        return [false, null];
1✔
87
                }
88

89
                // Ensure null is converted to string to avoid deprecation warning
90
                $key = gettype($value) === 'double' ? (int) $value : ($value ?? '');
1✔
91

92
                if (isset($this->replacements[$key])) {
1✔
NEW
93
                        return [true, $this->replacements[$key]];
×
94
                }
95

96
                return [false, null];
1✔
97
        }
98

99
}
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