GenerateFilesCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 19.61 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 0
dl 10
loc 51
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
B execute() 10 33 3
A _slugify() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace JPInfinity\FatcowIconsBundle\Command;
4
5
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6
use Symfony\Component\Console\Input\InputArgument;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Generate SCSS and LESS files.
13
 *
14
 * @author Julien Peltier <[email protected]>
15
 */
16
class GenerateFilesCommand extends ContainerAwareCommand
17
{
18
    protected function configure()
19
    {
20
        $this
21
            ->setName('fatcowicons:generate')
22
            ->setDescription('Generates the scss files corresponding on the icons availables.')
23
        ;
24
    }
25
26
    protected function execute(InputInterface $input, OutputInterface $output)
27
    {
28
        $scssDir = realpath(__DIR__ .'/../Resources/scss');
29
30
        // ICONS 16x16
31
        $fp = fopen($scssDir . '/_fatcow16.scss', 'w+');
32
        $content = "";
33
        $icons16 = glob(__DIR__ .'/../Resources/public/images/icons16x16/*.{png,jpg,gif}', GLOB_BRACE);
34 View Code Duplication
        foreach($icons16 as $img)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
        {
36
            $image = pathinfo($img);
37
            $content .= sprintf('.fci-%s {background-image:url(\'#{$icon16}/%s\');}'.PHP_EOL, $this->_slugify($image['filename']), basename($img));
38
        }
39
        fwrite($fp, $content);
40
        fclose($fp);
41
        $output->writeln(sprintf('Icons 16x16 - %d icons available', count($icons16)));
42
43
        // ICONS 32x32
44
        $fp = fopen($scssDir . '/_fatcow32.scss', 'w+');
45
        $content = "";
46
        $icons32 = glob(__DIR__ .'/../Resources/public/images/icons32x32/*.{png,jpg,gif}', GLOB_BRACE);
47 View Code Duplication
        foreach($icons32 as $img)
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
        {
49
            $image = pathinfo($img);
50
            $content .= sprintf('.fci32-%s {background-image:url(\'#{$icon32}/%s\');}'.PHP_EOL, $this->_slugify($image['filename']), basename($img));
51
        }
52
        fwrite($fp, $content);
53
        fclose($fp);
54
        $output->writeln(sprintf('Icons 32x32 - %d icons available', count($icons32)));
55
56
        $output->writeln('===');
57
        $output->writeln('You must generate the css files');
58
    }
59
60
    private function _slugify($str)
61
    {
62
        $str = preg_replace('`[^[:alnum:]]`', ' ', strtolower($str));
63
        $str = preg_replace('`[^[:alnum:]]`', '-', trim($str));
64
        return $str;
65
    }
66
}
67