BannerService   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 8
lcom 0
cbo 2
dl 0
loc 41
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdditionalCss() 0 16 6
A getAdditionalCssFile() 0 9 2
1
<?php
2
namespace DERHANSEN\SfBanners\Service;
3
4
/*
5
 * This file is part of the Extension "sf_banners" for TYPO3 CMS.
6
 *
7
 * For the full copyright and license information, please read the
8
 * LICENSE.txt file that was distributed with this source code.
9
 */
10
11
use TYPO3\CMS\Core\Utility\GeneralUtility;
12
13
/**
14
 * Banner Service
15
 *
16
 * @author Torben Hansen <[email protected]>
17
 */
18
class BannerService
19
{
20
    /**
21
     * Returns a string with additional CSS for the given banners
22
     *
23
     * @param array $banners Banners
24
     * @return string
25
     */
26
    public function getAdditionalCss($banners)
27
    {
28
        $ret = '';
29
        foreach ($banners as $banner) {
30
            /** @var \DERHANSEN\SfBanners\Domain\Model\Banner $banner */
31
            if ($banner->getMarginTop() > 0 || $banner->getMarginRight() > 0 ||
32
                $banner->getMarginBottom() > 0 || $banner->getMarginLeft() > 0
33
            ) {
34
                $bannerCss = '.banner-' . $banner->getUid() . ' { margin: ' . $banner->getMarginTop() .
35
                    'px ' . $banner->getMarginRight() . 'px ' . $banner->getMarginBottom() . 'px ' .
36
                    $banner->getMarginLeft() . 'px; }' . chr(10) . chr(13);
37
                $ret .= $bannerCss;
38
            }
39
        }
40
        return $ret;
41
    }
42
43
    /**
44
     * Returns the filename of the additional CSS for the banners
45
     *
46
     * @param array $banners Banners
47
     * @return string
48
     */
49
    public function getAdditionalCssFile($banners)
50
    {
51
        $filename = '';
52
        $css = $this->getAdditionalCss($banners);
53
        if ($css !== '') {
54
            $filename = GeneralUtility::writeStyleSheetContentToTemporaryFile($css);
55
        }
56
        return $filename;
57
    }
58
}
59