Completed
Push — master ( f886ea...29bcb1 )
by Andrea
34:08 queued 28:42
created

PannelloAmministrazioneController::indexAction()   C

Complexity

Conditions 9
Paths 64

Size

Total Lines 79
Code Lines 58

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 47
CRAP Score 9.1763

Importance

Changes 0
Metric Value
dl 0
loc 79
ccs 47
cts 54
cp 0.8704
rs 5.6693
c 0
b 0
f 0
cc 9
eloc 58
nc 64
nop 0
crap 9.1763

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Fi\PannelloAmministrazioneBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\Request;
7
use Symfony\Component\HttpFoundation\Response;
8
use Symfony\Component\Finder\Finder;
9
use Symfony\Component\Filesystem\Filesystem;
10
use Symfony\Component\Process\Process;
11
use Fi\OsBundle\DependencyInjection\OsFunctions;
12
use Fi\PannelloAmministrazioneBundle\DependencyInjection\Commands;
13
use Fi\PannelloAmministrazioneBundle\DependencyInjection\PannelloAmministrazioneUtils;
14
use Fi\PannelloAmministrazioneBundle\DependencyInjection\LockSystem;
15
use Fi\PannelloAmministrazioneBundle\DependencyInjection\ProjectPath;
16
17
class PannelloAmministrazioneController extends Controller
18
{
19
20
    protected $apppaths;
21
22 1
    public function indexAction()
23
    {
24 1
        $finder = new Finder();
25 1
        $fs = new Filesystem();
26 1
        $this->apppaths = new ProjectPath($this->container);
27
28 1
        $projectDir = $this->apppaths->getRootPath();
29 1
        $bundlelists = $this->container->getParameter('kernel.bundles');
30 1
        $bundles = array();
31 1
        foreach ($bundlelists as $bundle) {
32 1
            if (substr($bundle, 0, 2) === 'Fi') {
33 1
                $bundle = str_replace('\\', '/', $bundle);
34 1
                $bundlepath = $this->apppaths->getSrcPath() . DIRECTORY_SEPARATOR . substr($bundle, 0, strripos($bundle, '/'));
35 1
                if ($fs->exists($bundlepath)) {
36 1
                    $bundles[] = substr($bundle, 0, strripos($bundle, '/'));
37
                }
38
            }
39
        }
40 1
        $docDir = $this->apppaths->getDocPath();
41
42 1
        $mwbs = array();
43
44 1
        if ($fs->exists($docDir)) {
45 1
            $finder->in($docDir)->files()->name('*.mwb');
46 1
            foreach ($finder as $file) {
47 1
                $mwbs[] = $file->getBasename();
48
            }
49
        }
50
51 1
        if ($fs->exists($projectDir . '/.svn')) {
52
            $svn = true;
53
        } else {
54 1
            $svn = false;
55
        }
56
57 1
        if ($fs->exists($projectDir . '/.git')) {
58
            $git = true;
59
        } else {
60 1
            $git = false;
61
        }
62
63 1
        if (!OsFunctions::isWindows()) {
64 1
            $delcmd = 'rm -rf';
65 1
            $delfoldercmd = 'rm -rf';
0 ignored issues
show
Unused Code introduced by
$delfoldercmd is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
66 1
            $setfilelock = "touch " .$this->getParameter("maintenanceLockFilePath");
67 1
            $remfilelock = "rm " .$this->getParameter("maintenanceLockFilePath");
68 1
            $windows = false;
69
        } else {
70
            $delcmd = 'del';
71
            $delfoldercmd = 'rmdir /s';
0 ignored issues
show
Unused Code introduced by
$delfoldercmd is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
72
            $setfilelock = 'echo $null >> ' .$this->getParameter("maintenanceLockFilePath");
73
            $remfilelock = "del " .$this->getParameter("maintenanceLockFilePath");
74
            $windows = true;
75
        }
76
77 1
        $dellockfile = $delcmd . ' ' . $this->apppaths->getCachePath() . DIRECTORY_SEPARATOR . 'running.run';
78 1
        $delcomposerfile = $delcmd . ' ' . $projectDir . DIRECTORY_SEPARATOR . 'composer.lock';
79 1
        $dellogsfiles = $delcmd . ' ' . $this->apppaths->getLogsPath() . DIRECTORY_SEPARATOR . '*';
80 1
        $delcacheprodfiles = $delcmd . ' ' . $this->apppaths->getCachePath() . DIRECTORY_SEPARATOR . 'prod' . DIRECTORY_SEPARATOR . '*';
81 1
        $delcachedevfiles = $delcmd . ' ' . $this->apppaths->getCachePath() . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . '*';
82 1
        $setmaintenancefile = $setfilelock;
83 1
        $remmaintenancefile = $remfilelock;
84
85
        $comandishell = array(
86 1
            'lockfile' => $this->fixSlash($dellockfile),
87 1
            'composerlock' => $this->fixSlash($delcomposerfile),
88 1
            'logsfiles' => $this->fixSlash($dellogsfiles),
89 1
            'cacheprodfiles' => $this->fixSlash($delcacheprodfiles),
90 1
            'cachedevfiles' => $this->fixSlash($delcachedevfiles),
91 1
            'setmaintenancefile' => $setmaintenancefile,
92 1
            'remmaintenancefile' => $remmaintenancefile,
93
        );
94
95 1
        $twigparms = array('svn' => $svn, 'git' => $git, 'bundles' => $bundles, 'mwbs' => $mwbs,
96 1
            'rootdir' => $this->fixSlash($projectDir),
97 1
            'comandishell' => $comandishell, 'iswindows' => $windows,);
98
99 1
        return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:index.html.twig', $twigparms);
100
    }
101
102 1
    private function fixSlash($path)
103
    {
104 1
        return str_replace('\\', '\\\\', $path);
105
    }
106
107
    public function aggiornaSchemaDatabaseAction()
108
    {
109
        if ((new LockSystem($this->container))->isLockedFile()) {
110
            return (new LockSystem($this->container))->lockedFunctionMessage();
111
        } else {
112
            (new LockSystem($this->container))->lockFile(true);
113
            $commands = new Commands($this->container);
114
            $result = $commands->aggiornaSchemaDatabase();
115
116
            (new LockSystem($this->container))->lockFile(false);
117
            $twigparms = array('errcode' => $result['errcode'], 'command' => $result['command'], 'message' => $result['message']);
118
119
            return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:outputcommand.html.twig', $twigparms);
120
        }
121
    }
122
123
    /* FORMS */
124
125
    public function generateFormCrudAction(Request $request)
126
    {
127
        if ((new LockSystem($this->container))->isLockedFile()) {
128
            return (new LockSystem($this->container))->lockedFunctionMessage();
129
        } else {
130
            $bundlename = $request->get('bundlename');
131
            $entityform = $request->get('entityform');
132
133
            (new LockSystem($this->container))->lockFile(true);
134
135
            $command = new Commands($this->container);
136
            $ret = $command->generateFormCrud($bundlename, $entityform);
137
138
            (new LockSystem($this->container))->lockFile(false);
139
            //$retcc = '';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
140
            if ($ret['errcode'] < 0) {
141
                return new Response($ret['message']);
142
            } else {
0 ignored issues
show
Unused Code introduced by
This else statement is empty and can be removed.

This check looks for the else branches of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These else branches can be removed.

if (rand(1, 6) > 3) {
print "Check failed";
} else {
    //print "Check succeeded";
}

could be turned into

if (rand(1, 6) > 3) {
    print "Check failed";
}

This is much more concise to read.

Loading history...
143
                //$retcc = $command->clearCacheEnv($this->container->get('kernel')->getEnvironment());
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
144
            }
145
            $twigparms = array('errcode' => $ret['errcode'], 'command' => $ret['command'], 'message' => $ret['message']);
146
147
            return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:outputcommand.html.twig', $twigparms);
148
        }
149
    }
150
151
    /* ENTITIES */
152
153
    public function generateEntityAction(Request $request)
154
    {
155
        if ((new LockSystem($this->container))->isLockedFile()) {
156
            return (new LockSystem($this->container))->lockedFunctionMessage();
157
        } else {
158
            (new LockSystem($this->container))->lockFile(true);
159
            $wbFile = $request->get('file');
160
            $bundlePath = $request->get('bundle');
161
            $commands = new Commands($this->container);
162
            $ret = $commands->generateEntity($wbFile, $bundlePath);
163
            (new LockSystem($this->container))->lockFile(false);
164
            return new Response($ret['message']);
165
        }
166
    }
167
168
    /* ENTITIES */
169
170
    public function generateEntityClassAction(Request $request)
171
    {
172
        if ((new LockSystem($this->container))->isLockedFile()) {
173
            return (new LockSystem($this->container))->lockedFunctionMessage();
174
        } else {
175
            (new LockSystem($this->container))->lockFile(true);
176
            $bundlePath = $request->get('bundle');
177
            $commands = new Commands($this->container);
178
            $ret = $commands->generateEntityClass($bundlePath);
179
            (new LockSystem($this->container))->lockFile(false);
180
181
            return new Response($ret['message']);
182
        }
183
    }
184
185
    /* BUNDLE */
186
187
    public function generateBundleAction(Request $request)
188
    {
189
        $this->apppaths = new ProjectPath($this->container);
190
        if ((new LockSystem($this->container))->isLockedFile()) {
191
            return (new LockSystem($this->container))->lockedFunctionMessage();
192
        } else {
193
            (new LockSystem($this->container))->lockFile(true);
194
            $commands = new Commands($this->container);
195
            $bundleName = $request->get('bundlename');
196
            $result = $commands->generateBundle($bundleName);
197
            if ($result["errcode"] >= 0) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
198
                //$msg = "\nPer abilitare il nuovo bundle nel kernel pulire la cache e aggiornare la pagina";
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
199
                //$alert = '<script type="text/javascript">alert("' . $msg . '");location.reload();</script>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
200
                //$result['message'] = $result['message'] . $msg;
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
            }
202
            (new LockSystem($this->container))->lockFile(false);
203
            //Uso exit perchè la render avendo creato un nuovo bundle schianta perchè non è caricato nel kernel il nuovo bundle ancora
204
            //exit;
205
            $twigparms = array('errcode' => $result['errcode'], 'command' => $result['command'], 'message' => $result['message']);
206
207
            //$commands->clearcache();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
208
            //$this->container->get('kernel')->shutdown();
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
209
            //$this->container->get('kernel')->boot();
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
210
211
            return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:outputcommand.html.twig', $twigparms);
212
        }
213
    }
214
215
    /* VCS (GIT,SVN) */
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
216
217
    public function getVcsAction()
218
    {
219
        set_time_limit(0);
220
        $this->apppaths = new ProjectPath($this->container);
221
        if ((new LockSystem($this->container))->isLockedFile()) {
222
            return (new LockSystem($this->container))->lockedFunctionMessage();
223
        } else {
224
            (new LockSystem($this->container))->lockFile(true);
225
            $commands = new Commands($this->container);
226
            $result = $commands->getVcs();
227
            (new LockSystem($this->container))->lockFile(false);
228
            if ($result['errcode'] < 0) {
229
                $responseout = '<pre>Errore nel comando: <i style = "color: white;">' . $result['command'] . '</i>'
230
                        . '<br/><i style = "color: red;">' . nl2br($result['errmsg']) . '</i></pre>';
231
            } else {
232
                $responseout = '<pre>Eseguito comando: <i style = "color: white;">' . $result['command'] . '</i><br/>' .
233
                        nl2br($result['errmsg']) . '</pre>';
234
            }
235
236
            return new Response($responseout);
237
        }
238
    }
239
240
    /* CLEAR CACHE */
241
242
    /**
243
     * Suppress PMD warnings per exit.
244
     *
245
     * @SuppressWarnings(PHPMD)
246
     */
247
    public function clearCacheAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
248
    {
249
        set_time_limit(0);
250
        if ((new LockSystem($this->container))->isLockedFile()) {
251
            return (new LockSystem($this->container))->lockedFunctionMessage();
252
        } else {
253
            (new LockSystem($this->container))->lockFile(true);
254
            $commands = new Commands($this->container);
255
            $result = $commands->clearcache();
256
257
            (new LockSystem($this->container))->lockFile(false);
258
259
            /* Uso exit perchè new response avendo cancellato la cache schianta non avendo più a disposizione i file */
260
            //return $commanddev . '<br/>' . $cmdoutputdev . '<br/><br/>' . $commandprod . '<br/>' . $cmdoutputprod;
261
            //return new Response(nl2br($result));
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
262
            exit(nl2br($result));
263
        }
264
    }
265
266
    /* CLEAR CACHE */
267
268
    public function symfonyCommandAction(Request $request)
269
    {
270
        set_time_limit(0);
271
        $comando = $request->get('symfonycommand');
272
        if ((new LockSystem($this->container))->isLockedFile()) {
273
            return (new LockSystem($this->container))->lockedFunctionMessage();
274
        } else {
275
            (new LockSystem($this->container))->lockFile(true);
276
            $this->apppaths = new ProjectPath($this->container);
277
            $pammutils = new PannelloAmministrazioneUtils($this->container);
278
            $phpPath = OsFunctions::getPHPExecutableFromPath();
279
            $result = $pammutils->runCommand($phpPath . ' ' . $this->apppaths->getConsole() . ' ' . $comando);
280
281
            (new LockSystem($this->container))->lockFile(false);
282
            if ($result['errcode'] < 0) {
283
                $responseout = 'Errore nel comando: <i style = "color: white;">' .
284
                        str_replace(';', '<br/>', str_replace('&&', '<br/>', $comando)) .
285
                        '</i><br/><i style = "color: red;">' . nl2br($result['errmsg']) . '</i>';
286
287
                return new Response($responseout);
288
            }
289
            $responseout = '<pre>Eseguito comando:<br/><br/><i style = "color: white;">' .
290
                    str_replace(';', '<br/>', str_replace('&&', '<br/>', $comando)) . '</i><br/><br/>' .
291
                    str_replace("\n", '<br/>', $result['errmsg']) . '</pre>';
292
293
            return new Response($responseout);
294
        }
295
    }
296
297
    /**
298
     * Suppress PMD warnings per exit.
299
     *
300
     * @SuppressWarnings(PHPMD)
301
     */
302
    public function unixCommandAction(Request $request)
303
    {
304
        set_time_limit(0);
305
        $pammutils = new PannelloAmministrazioneUtils($this->container);
306
        $command = $request->get('unixcommand');
307
        if (!OsFunctions::isWindows()) {
308
            $lockdelcmd = 'rm -rf ';
309
        } else {
310
            $lockdelcmd = 'del ';
311
        }
312
        //Se viene lanciato il comando per cancellare il file di lock su bypassa tutto e si lancia
313
        $filelock = str_replace('\\', '\\\\', (new LockSystem($this->container))->getFileLock());
314
        if (str_replace('\\\\', '/', $command) == str_replace('\\\\', '\\', $lockdelcmd . $filelock)) {
315
            $fs = new Filesystem();
316
            if ((!($fs->exists($filelock)))) {
317
                return new Response('Non esiste il file di lock: <i style = "color: white;">' . $filelock . '</i><br/>');
318
            } else {
319
                $result = $pammutils->runCommand($command);
320
321
                // eseguito deopo la fine del comando
322
                if ($result['errmsg'] < 0) {
323
                    $responseout = 'Errore nel comando: <i style = "color: white;">' .
324
                            str_replace(';', '<br/>', str_replace('&&', '<br/>', $command)) .
325
                            '</i><br/><i style = "color: red;">' . str_replace("\n", '<br/>', $result['errmsg']) . '</i>';
326
327
                    exit(nl2br($responseout));
328
                }
329
330
                return new Response('File di lock cancellato');
331
            }
332
        }
333
334
        if ((new LockSystem($this->container))->isLockedFile()) {
335
            return (new LockSystem($this->container))->lockedFunctionMessage();
336
        } else {
337
            (new LockSystem($this->container))->lockFile(true);
338
            //$phpPath = OsFunctions::getPHPExecutableFromPath();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
339
            $result = $pammutils->runCommand($command);
340
341
            (new LockSystem($this->container))->lockFile(false);
342
            // eseguito deopo la fine del comando
343
            if ($result['errcode'] < 0) {
344
                $errmsg = 'Errore nel comando: <i style = "color: white;">' .
345
                        str_replace(';', '<br/>', str_replace('&&', '<br/>', $command)) .
346
                        '</i><br/><i style = "color: red;">' . nl2br($result['errmsg']) . '</i>';
347
348
                //return new Response($errmsg);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
349
                exit(nl2br($errmsg));
350
                //Uso exit perchè new response avendo cancellato la cache schianta non avendo più a disposizione i file
351
                //return;
352
                /* return new Response('Errore nel comando: <i style = "color: white;">' .
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
353
                 * $command . '</i><br/><i style = "color: red;">' . str_replace("\n", '<br/>', $process->getErrorOutput()) . '</i>'); */
354
            }
355
            $msgok = '<pre>Eseguito comando:<br/><i style = "color: white;"><br/>' .
356
                    str_replace(';', '<br/>', str_replace('&&', '<br/>', $command)) . '</i><br/>' .
357
                    nl2br($result['errmsg']) . '</pre>';
358
            //Uso exit perchè new response avendo cancellato la cache schianta non avendo più a disposizione i file
359
            //return new Response($msgok);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
360
            exit(nl2br($msgok));
361
            //return;
362
            /* return new Response('<pre>Eseguito comando: <i style = "color: white;">' . $command .
0 ignored issues
show
Unused Code Comprehensibility introduced by
48% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
363
             * '</i><br/>' . str_replace("\n", "<br/>", $process->getOutput()) . "</pre>"); */
364
        }
365
    }
366
367
    public function phpunittestAction(Request $request)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
368
    {
369
        set_time_limit(0);
370
        $this->apppaths = new ProjectPath($this->container);
371
        if ((new LockSystem($this->container))->isLockedFile()) {
372
            return (new LockSystem($this->container))->lockedFunctionMessage();
373
        } else {
374
            if (!OsFunctions::isWindows()) {
375
                (new LockSystem($this->container))->lockFile(true);
376
                //$phpPath = OsFunctions::getPHPExecutableFromPath();
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
377
                $sepchr = OsFunctions::getSeparator();
378
                $phpPath = OsFunctions::getPHPExecutableFromPath();
379
380
                // Questo codice per versioni che usano un symfony 2 o 3
381
                if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
382
                    $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr .
383
                            $phpPath . ' ' . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phpunit';
384
                } else {
385
                    $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr .
386
                            $phpPath . ' ' . 'bin' . DIRECTORY_SEPARATOR . 'phpunit -c app';
387
                }
388
389
                $process = new Process($command);
390
                $process->run();
391
392
                (new LockSystem($this->container))->lockFile(false);
393
                // eseguito deopo la fine del comando
394
                /* if (!$process->isSuccessful()) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
52% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
395
                  return new Response('Errore nel comando: <i style = "color: white;">' .
396
                 * $command . '</i><br/><i style = "color: red;">' . str_replace("\n",
397
                 * '<br/>', $process->getErrorOutput()) . '</i>');
398
                  } */
399
                $responseout = '<pre>Eseguito comando: <i style = "color: white;">' . $command . '</i><br/>' .
400
                        str_replace("\n", '<br/>', $process->getOutput()) . '</pre>';
401
402
                return new Response($responseout);
403
            } else {
404
                return new Response('Non previsto in ambiente windows!');
405
            }
406
        }
407
    }
408
}
409