Passed
Pull Request — master (#5614)
by Angel Fernando Quiroz
08:27
created

Version20240704185300   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
dl 0
loc 35
rs 10
c 1
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 25 3
A getDescription() 0 3 1
1
<?php
2
3
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
4
5
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo;
6
use Doctrine\DBAL\Schema\Schema;
7
use Symfony\Component\Filesystem\Filesystem;
8
use Symfony\Component\Finder\Finder;
9
10
class Version20240704185300 extends AbstractMigrationChamilo
11
{
12
    public function getDescription(): string
13
    {
14
        return "Fix stylesheet and theme settings and move theme directory during development";
15
    }
16
17
    /**
18
     * @inheritDoc
19
     */
20
    public function up(Schema $schema): void
21
    {
22
        $this->addSql("DELETE FROM settings_current WHERE variable IN ('stylesheets', 'theme')");
23
24
        $kernel = $this->container->get('kernel');
0 ignored issues
show
Bug introduced by
The method get() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        /** @scrutinizer ignore-call */ 
25
        $kernel = $this->container->get('kernel');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
25
        $rootPath = $kernel->getProjectDir();
26
27
        $themeDirectory = $rootPath.'/var/theme';
28
        $themesDirectory = $rootPath.'/var/themes';
29
30
        $finder = new Finder();
31
        $filesystem = new Filesystem();
32
33
        $finder->directories()->in($themeDirectory)->depth('== 0');
34
35
        foreach ($finder as $entry) {
36
            if ($entry->isDir()) {
37
                error_log(
38
                    sprintf(
39
                        "Moving theme directory: %s %s",
40
                        $entry->getRealPath(),
41
                        $themesDirectory.'/'
42
                    )
43
                );
44
                $filesystem->rename($entry->getRealPath(), $themesDirectory.'/'.$entry->getRelativePathname());
45
            }
46
        }
47
    }
48
}