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

FluidTYPO3 / vhs / 25130651484

29 Apr 2026 07:55PM UTC coverage: 72.022%. Remained the same
25130651484

Pull #1968

github

web-flow
Merge 04fc0907a into 801f964d0
Pull Request #1968: [TASK] Replace non-canonical cast names (boolean) and (integer) with (bool) and (int)

100 of 129 new or added lines in 53 files covered. (77.52%)

5648 of 7842 relevant lines covered (72.02%)

19.99 hits per line

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

72.41
/Classes/ViewHelpers/Media/Image/AbstractImageInfoViewHelper.php
1
<?php
2
namespace FluidTYPO3\Vhs\ViewHelpers\Media\Image;
3

4
/*
5
 * This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.md file that was distributed with this source code.
9
 */
10

11
use FluidTYPO3\Vhs\Proxy\ResourceFactoryProxy;
12
use FluidTYPO3\Vhs\Utility\ResourceUtility;
13
use TYPO3\CMS\Core\Resource\FileReference as CoreFileReference;
14
use TYPO3\CMS\Core\Utility\GeneralUtility;
15
use TYPO3\CMS\Extbase\Domain\Model\FileReference as ExtbaseFileReference;
16
use FluidTYPO3\Vhs\Core\ViewHelper\AbstractViewHelper;
17
use TYPO3Fluid\Fluid\Core\ViewHelper\Exception;
18

19
/**
20
 * Base class: Media\Image view helpers.
21
 */
22
abstract class AbstractImageInfoViewHelper extends AbstractViewHelper
23
{
24
    /**
25
     * @var ResourceFactoryProxy
26
     */
27
    protected $resourceFactory;
28

29
    /**
30
     * @var boolean
31
     */
32
    protected $escapeOutput = false;
33

34
    /**
35
     * Construct resource factory
36
     */
37
    public function __construct()
38
    {
39
        /** @var ResourceFactoryProxy $resourceFactory */
40
        $resourceFactory = GeneralUtility::makeInstance(ResourceFactoryProxy::class);
×
41
        $this->resourceFactory = $resourceFactory;
×
42
    }
43

44
    public function initializeArguments(): void
45
    {
46
        $this->registerArgument(
21✔
47
            'src',
21✔
48
            'mixed',
21✔
49
            'Path to or id of the image file to determine info for. In case a FileReference is supplied, ' .
21✔
50
            'treatIdAsUid and treatIdAsReference will automatically be activated.',
21✔
51
            true
21✔
52
        );
21✔
53
        $this->registerArgument(
21✔
54
            'treatIdAsUid',
21✔
55
            'boolean',
21✔
56
            'If TRUE, the path argument is treated as a resource uid.'
21✔
57
        );
21✔
58
        $this->registerArgument(
21✔
59
            'treatIdAsReference',
21✔
60
            'boolean',
21✔
61
            'If TRUE, the path argument is treated as a reference uid and will be resolved to a resource via ' .
21✔
62
            'sys_file_reference.',
21✔
63
            false,
21✔
64
            false
21✔
65
        );
21✔
66
    }
67

68
    public function getInfo(): array
69
    {
70
        /** @var string|int|CoreFileReference|ExtbaseFileReference|null $src */
71
        $src = $this->arguments['src'];
84✔
72
        $treatIdAsUid = (bool) $this->arguments['treatIdAsUid'];
84✔
73
        $treatIdAsReference = (bool) $this->arguments['treatIdAsReference'];
84✔
74

75
        if (null === $src) {
84✔
76
            /** @var string|int|CoreFileReference|ExtbaseFileReference|null $src */
77
            $src = $this->renderChildren();
84✔
78
            if (null === $src) {
84✔
79
                return [];
21✔
80
            }
81
        }
82

83
        if ($src instanceof CoreFileReference || $src instanceof ExtbaseFileReference) {
63✔
84
            $src = $src->getUid();
×
85
            $treatIdAsUid = false;
×
86
            $treatIdAsReference = true;
×
87
        }
88

89
        if ($treatIdAsUid || $treatIdAsReference) {
63✔
NEW
90
            $id = (int) $src;
×
91
            $info = [];
×
92
            if ($treatIdAsUid) {
×
93
                $info = $this->getInfoByUid($id);
×
94
            } elseif ($treatIdAsReference) {
×
95
                $info = $this->getInfoByReference($id);
×
96
            }
97
        } else {
98
            $file = GeneralUtility::getFileAbsFileName((string) $src);
63✔
99
            if (!file_exists($file) || is_dir($file)) {
63✔
100
                throw new Exception(
42✔
101
                    'Cannot determine info for "' . $file . '". File does not exist or is a directory.',
42✔
102
                    1357066532
42✔
103
                );
42✔
104
            }
105
            $imageSize = getimagesize($file);
21✔
106
            $info = [
21✔
107
                'width'  => $imageSize[0] ?? '',
21✔
108
                'height' => $imageSize[1] ?? '',
21✔
109
                'type'   => $imageSize['mime'] ?? '',
21✔
110
            ];
21✔
111
        }
112

113
        return $info;
21✔
114
    }
115

116
    public function getInfoByReference(int $id): array
117
    {
118
        $fileReference = $this->resourceFactory->getFileReferenceObject($id);
×
119
        $file = $fileReference->getOriginalFile();
×
120
        return ResourceUtility::getFileArray($file);
×
121
    }
122

123
    public function getInfoByUid(int $uid): array
124
    {
125
        $file = $this->resourceFactory->getFileObject($uid);
×
126
        return ResourceUtility::getFileArray($file);
×
127
    }
128
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc