Fork me on GitHub
a Sensio Labs Product

Brazilian Kangaroo (v3.17.0) edition

Rule nullable_type_declaration_for_default_null_value

Adds or removes ? before type declarations for parameters with a default null value.

Description

Rule is applied only in a PHP 7.1+ environment.

Configuration

use_nullable_type_declaration

Whether to add or remove ? before type declarations for parameters with a default null value.

Allowed types: bool

Default value: true

Examples

Example #1

Default configuration.

--- Original
+++ New
 <?php
-function sample(string $str = null)
+function sample(?string $str = null)
 {}

Example #2

With configuration: ['use_nullable_type_declaration' => false].

--- Original
+++ New
 <?php
-function sample(?string $str = null)
+function sample(string $str = null)
 {}

Rule sets

The rule is part of the following rule set:

@Symfony

Using the @Symfony rule set will enable the nullable_type_declaration_for_default_null_value rule with the config below:

['use_nullable_type_declaration' => false]

The logo is © 2010-2022 Sensio Labs