FileUtility   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getFileByMetaData() 0 9 2
A getFileByUid() 0 5 1
1
<?php
2
3
/**
4
 * Utility functions for files.
5
 */
6
7
namespace HDNET\Focuspoint\Utility;
8
9
use HDNET\Focuspoint\Domain\Repository\SysFileMetadataRepository;
10
use TYPO3\CMS\Core\Resource\ResourceFactory;
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
13
/**
14
 * Utility functions for files.
15
 */
16
class FileUtility
17
{
18
    /**
19
     * Get the file object of the given cell information.
20
     *
21
     * @param int $uid
22
     *
23
     * @throws \Exception
24
     * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
25
     *
26
     * @return \TYPO3\CMS\Core\Resource\File
27
     */
28
    public static function getFileByMetaData($uid)
29
    {
30
        $row = GeneralUtility::makeInstance(SysFileMetadataRepository::class)->findByUid((int) $uid);
31
        if (!isset($row['file'])) {
32
            throw new \Exception('File not found in metadata', 1475144028);
33
        }
34
35
        return self::getFileByUid((int) $row['file']);
36
    }
37
38
    /**
39
     * Get the file object of the given cell information.
40
     *
41
     * @param int $uid
42
     *
43
     * @throws \Exception
44
     * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
45
     *
46
     * @return \TYPO3\CMS\Core\Resource\File
47
     */
48
    public static function getFileByUid($uid)
49
    {
50
        return ResourceFactory::getInstance()
51
            ->getFileObject($uid);
52
    }
53
}
54