* Dariusz RumiƄski * * This source file is subject to the MIT license that is bundled * with this source code in the file LICENSE. */ namespace PhpCsFixer\Fixer\Phpdoc; use PhpCsFixer\AbstractPhpdocTypesFixer; use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface; use PhpCsFixer\FixerConfiguration\AllowedValueSubset; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; use PhpCsFixer\FixerDefinition\CodeSample; use PhpCsFixer\FixerDefinition\FixerDefinition; /** * @author Graham Campbell */ final class PhpdocScalarFixer extends AbstractPhpdocTypesFixer implements ConfigurationDefinitionFixerInterface { /** * The types to fix. * * @var array */ private static $types = [ 'boolean' => 'bool', 'callback' => 'callable', 'double' => 'float', 'integer' => 'int', 'real' => 'float', 'str' => 'string', ]; /** * {@inheritdoc} */ public function getDefinition() { return new FixerDefinition( 'Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.', [new CodeSample('setAllowedValues([new AllowedValueSubset(array_keys(self::$types))]) ->setDefault(['boolean', 'double', 'integer', 'real', 'str']) // TODO 3.0 add "callback" ->getOption(), ]); } /** * {@inheritdoc} */ protected function normalize($type) { if (\in_array($type, $this->configuration['types'], true)) { return self::$types[$type]; } return $type; } }