Skip to content

Commit 0b44a1d

Browse files
committed
added PHP 7.1 type hints
1 parent fe22e68 commit 0b44a1d

File tree

9 files changed

+26
-60
lines changed

9 files changed

+26
-60
lines changed

src/DI/Compiler.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,8 @@ public function generateCode(): array
258258

259259
/**
260260
* Adds service definitions from configuration.
261-
* @return void
262261
*/
263-
public static function loadDefinitions(ContainerBuilder $builder, array $services, string $namespace = null)
262+
public static function loadDefinitions(ContainerBuilder $builder, array $services, string $namespace = null): void
264263
{
265264
foreach ($services as $name => $def) {
266265
if (is_int($name)) {
@@ -310,9 +309,8 @@ public static function loadDefinitions(ContainerBuilder $builder, array $service
310309

311310
/**
312311
* Parses single service definition from configuration.
313-
* @return void
314312
*/
315-
public static function loadDefinition(ServiceDefinition $definition, $config, string $name = null)
313+
public static function loadDefinition(ServiceDefinition $definition, $config, string $name = null): void
316314
{
317315
if ($config === null) {
318316
return;

src/DI/Config/Adapters/IniAdapter.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ public function dump(array $data): string
113113

114114
/**
115115
* Recursive builds INI list.
116-
* @return void
117116
*/
118-
private static function build($input, &$output, $prefix)
117+
private static function build($input, &$output, $prefix): void
119118
{
120119
foreach ($input as $key => $val) {
121120
$key = str_replace(self::KEY_SEPARATOR, self::ESCAPED_KEY_SEPARATOR, $key);

src/DI/Config/Loader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ public function load(string $file): array
6161

6262
/**
6363
* Save configuration to file.
64-
* @return void
6564
*/
66-
public function save(array $data, string $file)
65+
public function save(array $data, string $file): void
6766
{
6867
if (file_put_contents($file, $this->getAdapter($file)->dump($data)) === false) {
6968
throw new Nette\IOException("Cannot write file '$file'.");

src/DI/Container.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ public function addService(string $name, $service)
8080

8181
/**
8282
* Removes the service from the container.
83-
* @return void
8483
*/
85-
public function removeService(string $name)
84+
public function removeService(string $name): void
8685
{
8786
$name = $this->meta[self::ALIASES][$name] ?? $name;
8887
unset($this->registry[$name]);
@@ -257,9 +256,8 @@ public function createInstance(string $class, array $args = [])
257256
/**
258257
* Calls all methods starting with with "inject" using autowiring.
259258
* @param object
260-
* @return void
261259
*/
262-
public function callInjects($service)
260+
public function callInjects($service): void
263261
{
264262
Extensions\InjectExtension::callInjects($this, $service);
265263
}

src/DI/ContainerBuilder.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ public function addDefinition(string $name, ServiceDefinition $definition = null
7878

7979
/**
8080
* Removes the specified service definition.
81-
* @return void
8281
*/
83-
public function removeDefinition(string $name)
82+
public function removeDefinition(string $name): void
8483
{
8584
$this->classListNeedsRefresh = true;
8685
$name = $this->aliases[$name] ?? $name;
@@ -141,9 +140,8 @@ public function addAlias(string $alias, string $service)
141140

142141
/**
143142
* Removes the specified alias.
144-
* @return void
145143
*/
146-
public function removeAlias(string $alias)
144+
public function removeAlias(string $alias): void
147145
{
148146
unset($this->aliases[$alias]);
149147
}
@@ -184,7 +182,7 @@ public function addExcludedClasses(array $types)
184182
* @return string|null service name or null
185183
* @throws ServiceCreationException
186184
*/
187-
public function getByType(string $type, bool $throw = false)
185+
public function getByType(string $type, bool $throw = false): ?string
188186
{
189187
$type = Helpers::normalizeClass($type);
190188

@@ -199,7 +197,7 @@ public function getByType(string $type, bool $throw = false)
199197
if ($throw) {
200198
throw new MissingServiceException("Service of type '$type' not found.");
201199
}
202-
return;
200+
return null;
203201

204202
} elseif (count($types[$type][true]) === 1) {
205203
return $types[$type][true][0];
@@ -272,10 +270,9 @@ public function getClassList(): array
272270

273271
/**
274272
* Generates $dependencies, $classList and normalizes class names.
275-
* @return void
276273
* @internal
277274
*/
278-
public function prepareClassList()
275+
public function prepareClassList(): void
279276
{
280277
unset($this->definitions[self::THIS_CONTAINER]);
281278
$this->addDefinition(self::THIS_CONTAINER)->setType(Container::class);
@@ -515,10 +512,7 @@ private function resolveEntityType($entity, array $recursive = [])
515512
}
516513

517514

518-
/**
519-
* @return void
520-
*/
521-
public function complete()
515+
public function complete(): void
522516
{
523517
$this->prepareClassList();
524518

@@ -699,10 +693,9 @@ public function normalizeEntity($entity)
699693

700694
/**
701695
* Converts @service or @\Class -> service name and checks its existence.
702-
* @return string|null
703696
* @internal
704697
*/
705-
public function getServiceName($arg)
698+
public function getServiceName($arg): ?string
706699
{
707700
if (!is_string($arg) || !preg_match('#^@[\w\\\\.][^:]*\z#', $arg)) {
708701
return null;

src/DI/ContainerLoader.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ public function getClassName($key): string
5353
}
5454

5555

56-
/**
57-
* @return void
58-
*/
59-
private function loadFile(string $class, callable $generator)
56+
private function loadFile(string $class, callable $generator): void
6057
{
6158
$file = "$this->tempDirectory/$class.php";
6259
if (!$this->isExpired($file) && (@include $file) !== false) { // @ file may not exist

src/DI/Extensions/InjectExtension.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,8 @@ public static function getInjectProperties($class): array
110110

111111
/**
112112
* Calls all methods starting with with "inject" using autowiring.
113-
* @return void
114113
*/
115-
public static function callInjects(DI\Container $container, $service)
114+
public static function callInjects(DI\Container $container, $service): void
116115
{
117116
if (!is_object($service)) {
118117
throw new Nette\InvalidArgumentException(sprintf('Service must be object, %s given.', gettype($service)));

src/DI/Helpers.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,8 @@ public static function prefixServiceName($config, string $namespace)
198198

199199
/**
200200
* Returns an annotation value.
201-
* @return string|null
202201
*/
203-
public static function parseAnnotation(\Reflector $ref, $name)
202+
public static function parseAnnotation(\Reflector $ref, $name): ?string
204203
{
205204
if (!Reflection::areCommentsAvailable()) {
206205
throw new Nette\InvalidStateException('You have to enable phpDoc comments in opcode cache.');
@@ -209,13 +208,11 @@ public static function parseAnnotation(\Reflector $ref, $name)
209208
if ($ref->getDocComment() && preg_match("#[\\s*]@$name(?:\\s++([^@]\\S*)?|$)#", trim($ref->getDocComment(), '/*'), $m)) {
210209
return $m[1] ?? '';
211210
}
211+
return null;
212212
}
213213

214214

215-
/**
216-
* @return string|null
217-
*/
218-
public static function getReturnType(\ReflectionFunctionAbstract $func)
215+
public static function getReturnType(\ReflectionFunctionAbstract $func): ?string
219216
{
220217
if ($type = Reflection::getReturnType($func)) {
221218
return $type;
@@ -230,6 +227,7 @@ public static function getReturnType(\ReflectionFunctionAbstract $func)
230227
return $type;
231228
}
232229
}
230+
return null;
233231
}
234232

235233

src/DI/ServiceDefinition.php

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ final class ServiceDefinition
5959

6060

6161
/**
62-
* @param string|null
6362
* @return static
6463
* @deprecated Use setType() instead.
6564
*/
66-
public function setClass($type)
65+
public function setClass(?string $type)
6766
{
6867
($this->notifier)();
6968
$this->type = $type;
@@ -78,31 +77,26 @@ public function setClass($type)
7877

7978

8079
/**
81-
* @return string|null
8280
* @deprecated Use getType() instead.
8381
*/
84-
public function getClass()
82+
public function getClass(): ?string
8583
{
8684
return $this->type;
8785
}
8886

8987

9088
/**
91-
* @param string|null
9289
* @return static
9390
*/
94-
public function setType($type)
91+
public function setType(?string $type)
9592
{
9693
($this->notifier)();
9794
$this->type = $type;
9895
return $this;
9996
}
10097

10198

102-
/**
103-
* @return string|null
104-
*/
105-
public function getType()
99+
public function getType(): ?string
106100
{
107101
return $this->type;
108102
}
@@ -119,10 +113,7 @@ public function setFactory($factory, array $args = [])
119113
}
120114

121115

122-
/**
123-
* @return Statement|null
124-
*/
125-
public function getFactory()
116+
public function getFactory(): ?Statement
126117
{
127118
return $this->factory;
128119
}
@@ -293,10 +284,7 @@ public function setImplement(string $interface)
293284
}
294285

295286

296-
/**
297-
* @return string|null
298-
*/
299-
public function getImplement()
287+
public function getImplement(): ?string
300288
{
301289
return $this->implement;
302290
}
@@ -315,10 +303,7 @@ public function setImplementMode(string $mode)
315303
}
316304

317305

318-
/**
319-
* @return string|null
320-
*/
321-
public function getImplementMode()
306+
public function getImplementMode(): ?string
322307
{
323308
return $this->implementMode;
324309
}

0 commit comments

Comments
 (0)