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

nette / di / 6739035766

02 Nov 2023 10:44PM UTC coverage: 52.037% (-41.8%) from 93.846%
6739035766

push

github

dg
x

1009 of 1939 relevant lines covered (52.04%)

0.52 hits per line

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

86.96
/src/DI/Definitions/Statement.php
1
<?php
2

3
/**
4
 * This file is part of the Nette Framework (https://nette.org)
5
 * Copyright (c) 2004 David Grudl (https://davidgrudl.com)
6
 */
7

8
declare(strict_types=1);
9

10
namespace Nette\DI\Definitions;
11

12
use Nette;
13
use Nette\Utils\Strings;
14

15

16
/**
17
 * Assignment or calling statement.
18
 *
19
 * @property string|array|Definition|Reference|null $entity
20
 */
21
final class Statement implements Nette\Schema\DynamicParameter
22
{
23
        use Nette\SmartObject;
24

25
        /** @var array */
26
        public $arguments;
27

28
        /** @var string|array|Definition|Reference|null */
29
        private $entity;
30

31

32
        /**
33
         * @param  string|array|Definition|Reference|null  $entity
34
         */
35
        public function __construct($entity, array $arguments = [])
1✔
36
        {
37
                if (
38
                        $entity !== null
1✔
39
                        && !is_string($entity) // Class, @service, not, tags, types, PHP literal, entity::member
1✔
40
                        && !$entity instanceof Definition
1✔
41
                        && !$entity instanceof Reference
1✔
42
                        && !(is_array($entity)
1✔
43
                                && array_keys($entity) === [0, 1]
1✔
44
                                && (is_string($entity[0])
1✔
45
                                        || $entity[0] instanceof self
1✔
46
                                        || $entity[0] instanceof Reference
1✔
47
                                        || $entity[0] instanceof Definition)
1✔
48
                        )) {
49
                        throw new Nette\InvalidArgumentException('Argument is not valid Statement entity.');
×
50
                }
51

52
                // normalize Class::method to [Class, method]
53
                if (is_string($entity) && Strings::contains($entity, '::') && !Strings::contains($entity, '?')) {
1✔
54
                        $entity = explode('::', $entity, 2);
1✔
55
                }
56

57
                if (is_string($entity) && substr($entity, 0, 1) === '@') { // normalize @service to Reference
1✔
58
                        $entity = new Reference(substr($entity, 1));
×
59
                } elseif (is_array($entity) && is_string($entity[0]) && substr($entity[0], 0, 1) === '@') {
1✔
60
                        $entity[0] = new Reference(substr($entity[0], 1));
×
61
                }
62

63
                $this->entity = $entity;
1✔
64
                $this->arguments = $arguments;
1✔
65
        }
1✔
66

67

68
        /** @return string|array|Definition|Reference|null */
69
        public function getEntity()
70
        {
71
                return $this->entity;
1✔
72
        }
73
}
74

75

76
class_exists(Nette\DI\Statement::class);
1✔
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