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

contributte / datagrid / 8230471191

11 Mar 2024 09:25AM UTC coverage: 34.102%. First build
8230471191

Pull #1060

github

radimvaculik
Fix phpstan
Pull Request #1060: [7.x] Next

117 of 435 new or added lines in 54 files covered. (26.9%)

1124 of 3296 relevant lines covered (34.1%)

0.34 hits per line

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

51.61
/src/Traits/TLink.php
1
<?php declare(strict_types = 1);
2

3
namespace Contributte\Datagrid\Traits;
4

5
use Contributte\Datagrid\Datagrid;
6
use Contributte\Datagrid\Exception\DatagridHasToBeAttachedToPresenterComponentException;
7
use Contributte\Datagrid\Exception\DatagridLinkCreationException;
8
use InvalidArgumentException;
9
use Nette\Application\UI\Component;
10
use Nette\Application\UI\InvalidLinkException;
11
use Nette\Application\UI\Presenter;
12
use UnexpectedValueException;
13

14
trait TLink
15
{
16

17
        /**
18
         * @throws DatagridHasToBeAttachedToPresenterComponentException
19
         * @throws InvalidArgumentException
20
         * @throws DatagridLinkCreationException
21
         * @throws UnexpectedValueException
22
         */
23
        protected function createLink(
1✔
24
                Datagrid $grid,
25
                string $href,
26
                array $params
27
        ): string
28
        {
29
                $targetComponent = $grid;
1✔
30

31
                $presenter = $grid->getPresenter();
1✔
32

33
                if (str_contains($href, ':')) {
1✔
34
                        return $presenter->link($href, $params);
×
35
                }
36

37
                for ($iteration = 0; $iteration < 10; $iteration++) {
1✔
38
                        $targetComponent = $targetComponent->getParent();
1✔
39

40
                        if (!$targetComponent instanceof Component) {
1✔
41
                                throw $this->createHierarchyLookupException($grid, $href, $params);
×
42
                        }
43

44
                        try {
45
                                $link = $targetComponent->link($href, $params);
1✔
46
                        } catch (InvalidLinkException) {
1✔
47
                                $link = false;
1✔
48
                        }
49

50
                        if (is_string($link)) {
1✔
51
                                if (
52
                                        str_starts_with($link, '#error') ||
1✔
53
                                        (strrpos($href, '!') !== false && str_starts_with($link, '#')) ||
1✔
54
                                        (in_array($presenter->invalidLinkMode, [Presenter::InvalidLinkWarning, Presenter::InvalidLinkSilent], true) && str_starts_with($link, '#'))
1✔
55
                                ) {
56
                                        continue; // Did not find signal handler
×
57
                                }
58

59
                                return $link; // Found signal handler!
1✔
60
                        } else {
61
                                continue; // Did not find signal handler
1✔
62
                        }
63
                }
64

65
                // Went 10 steps up to the Presenter and did not find any signal handler
66
                throw $this->createHierarchyLookupException($grid, $href, $params);
×
67
        }
68

69
        private function createHierarchyLookupException(
70
                Datagrid $grid,
71
                string $href,
72
                array $params
73
        ): DatagridLinkCreationException
74
        {
75
                $parent = $grid->getParent();
×
76
                $presenter = $grid->getPresenter();
×
77

78
                if ($parent === null) {
×
79
                        throw new UnexpectedValueException(
×
80
                                sprintf('%s can not live withnout a parent component', self::class)
×
81
                        );
82
                }
83

NEW
84
                $desiredHandler = $parent::class . '::handle' . ucfirst($href) . '()';
×
85

NEW
86
                return new DatagridLinkCreationException(
×
87
                        'Datagrid could not create link "'
88
                        . $href . '" - did not find any signal handler in componenet hierarchy from '
×
NEW
89
                        . $parent::class . ' up to the '
×
NEW
90
                        . $presenter::class . '. '
×
91
                        . 'Try adding handler ' . $desiredHandler
×
92
                );
93
        }
94

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