[TASK] Streamline phpdoc annotations in EXT:extbase
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Property / TypeConverter / IntegerConverter.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Property\TypeConverter;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * Converter which transforms a simple type to an integer, by simply casting it.
19 */
20 class IntegerConverter extends \TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter
21 {
22 /**
23 * @var array<string>
24 */
25 protected $sourceTypes = ['integer', 'string'];
26
27 /**
28 * @var string
29 */
30 protected $targetType = 'integer';
31
32 /**
33 * @var int
34 */
35 protected $priority = 10;
36
37 /**
38 * Actually convert from $source to $targetType, in fact a noop here.
39 *
40 * @param int|string $source
41 * @param string $targetType
42 * @param array $convertedChildProperties
43 * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
44 * @return int|\TYPO3\CMS\Extbase\Error\Error
45 */
46 public function convertFrom($source, $targetType, array $convertedChildProperties = [], \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration = null)
47 {
48 if ($source === null || (string)$source === '') {
49 return null;
50 }
51 if (!is_numeric($source)) {
52 return new \TYPO3\CMS\Extbase\Error\Error('"%s" is no integer.', 1332933658, [$source]);
53 }
54 return (int)$source;
55 }
56 }