ImageUtility   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 37
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllowedFileExtensions() 0 11 1
A isValidFileExtension() 0 10 2
1
<?php
2
3
/**
4
 * Image Utility.
5
 */
6
7
namespace HDNET\Focuspoint\Utility;
8
9
use TYPO3\CMS\Core\Utility\GeneralUtility;
10
use TYPO3\CMS\Core\Utility\PathUtility;
11
12
/**
13
 * Image Utility.
14
 */
15
class ImageUtility
16
{
17
    /**
18
     * Get the allowed file extensions for the focuspoint method.
19
     *
20
     * @return array
21
     */
22
    public static function getAllowedFileExtensions()
23
    {
24
        $configuredExtensions = GeneralUtility::trimExplode(
25
            ',',
26
            \mb_strtolower($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
27
            true
28
        );
29
        $ignoreExtensions = ['pdf', 'ai', 'tga'];
30
31
        return \array_diff($configuredExtensions, $ignoreExtensions);
32
    }
33
34
    /**
35
     * Check if the given path or extension is valid for the focuspoint.
36
     *
37
     * @param $pathOrExtension
38
     *
39
     * @return bool
40
     */
41
    public static function isValidFileExtension($pathOrExtension)
42
    {
43
        $pathOrExtension = \mb_strtolower($pathOrExtension);
44
        $validExtensions = self::getAllowedFileExtensions();
45
        if (\in_array($pathOrExtension, $validExtensions, true)) {
46
            return true;
47
        }
48
49
        return \in_array(PathUtility::pathinfo($pathOrExtension, PATHINFO_EXTENSION), $validExtensions, true);
50
    }
51
}
52