Completed
Push — master ( 67b803...4fd862 )
by Andrea
10:48
created

PannelloAmministrazioneController::indexAction()   C

Complexity

Conditions 9
Paths 64

Size

Total Lines 77
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 46
CRAP Score 9.1244

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 77
ccs 46
cts 52
cp 0.8846
rs 5.7699
cc 9
eloc 56
nc 64
nop 0
crap 9.1244

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
            $setfilelock = "touch " .$this->getParameter("maintenanceLockFilePath");
66 1
            $remfilelock = "rm " .$this->getParameter("maintenanceLockFilePath");
67 1
            $windows = false;
68
        } else {
69
            $delcmd = 'del';
70
            $setfilelock = 'echo $null >> ' .$this->getParameter("maintenanceLockFilePath");
71
            $remfilelock = "del " .$this->getParameter("maintenanceLockFilePath");
72
            $windows = true;
73
        }
74
75 1
        $dellockfile = $delcmd . ' ' . $this->apppaths->getCachePath() . DIRECTORY_SEPARATOR . 'running.run';
76 1
        $delcomposerfile = $delcmd . ' ' . $projectDir . DIRECTORY_SEPARATOR . 'composer.lock';
77 1
        $dellogsfiles = $delcmd . ' ' . $this->apppaths->getLogsPath() . DIRECTORY_SEPARATOR . '*';
78 1
        $delcacheprodfiles = $delcmd . ' ' . $this->apppaths->getCachePath() . DIRECTORY_SEPARATOR . 'prod' . DIRECTORY_SEPARATOR . '*';
79 1
        $delcachedevfiles = $delcmd . ' ' . $this->apppaths->getCachePath() . DIRECTORY_SEPARATOR . 'dev' . DIRECTORY_SEPARATOR . '*';
80 1
        $setmaintenancefile = $setfilelock;
81 1
        $remmaintenancefile = $remfilelock;
82
83
        $comandishell = array(
84 1
            'lockfile' => $this->fixSlash($dellockfile),
85 1
            'composerlock' => $this->fixSlash($delcomposerfile),
86 1
            'logsfiles' => $this->fixSlash($dellogsfiles),
87 1
            'cacheprodfiles' => $this->fixSlash($delcacheprodfiles),
88 1
            'cachedevfiles' => $this->fixSlash($delcachedevfiles),
89 1
            'setmaintenancefile' => $setmaintenancefile,
90 1
            'remmaintenancefile' => $remmaintenancefile,
91
        );
92
93 1
        $twigparms = array('svn' => $svn, 'git' => $git, 'bundles' => $bundles, 'mwbs' => $mwbs,
94 1
            'rootdir' => $this->fixSlash($projectDir),
95 1
            'comandishell' => $comandishell, 'iswindows' => $windows,);
96
97 1
        return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:index.html.twig', $twigparms);
98
    }
99
100 1
    private function fixSlash($path)
101
    {
102 1
        return str_replace('\\', '\\\\', $path);
103
    }
104
105
    public function aggiornaSchemaDatabaseAction()
106
    {
107
        if ((new LockSystem($this->container))->isLockedFile()) {
108
            return (new LockSystem($this->container))->lockedFunctionMessage();
109
        } else {
110
            (new LockSystem($this->container))->lockFile(true);
111
            $commands = new Commands($this->container);
112
            $result = $commands->aggiornaSchemaDatabase();
113
114
            (new LockSystem($this->container))->lockFile(false);
115
            $twigparms = array('errcode' => $result['errcode'], 'command' => $result['command'], 'message' => $result['message']);
116
117
            return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:outputcommand.html.twig', $twigparms);
118
        }
119
    }
120
121
    /* FORMS */
122
123
    public function generateFormCrudAction(Request $request)
124
    {
125
        if ((new LockSystem($this->container))->isLockedFile()) {
126
            return (new LockSystem($this->container))->lockedFunctionMessage();
127
        } else {
128
            $bundlename = $request->get('bundlename');
129
            $entityform = $request->get('entityform');
130
131
            (new LockSystem($this->container))->lockFile(true);
132
133
            $command = new Commands($this->container);
134
            $ret = $command->generateFormCrud($bundlename, $entityform);
135
136
            (new LockSystem($this->container))->lockFile(false);
137
            //$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...
138
            if ($ret['errcode'] < 0) {
139
                return new Response($ret['message']);
140
            } 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...
141
                //$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...
142
            }
143
            $twigparms = array('errcode' => $ret['errcode'], 'command' => $ret['command'], 'message' => $ret['message']);
144
145
            return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:outputcommand.html.twig', $twigparms);
146
        }
147
    }
148
149
    /* ENTITIES */
150
151
    public function generateEntityAction(Request $request)
152
    {
153
        if ((new LockSystem($this->container))->isLockedFile()) {
154
            return (new LockSystem($this->container))->lockedFunctionMessage();
155
        } else {
156
            (new LockSystem($this->container))->lockFile(true);
157
            $wbFile = $request->get('file');
158
            $bundlePath = $request->get('bundle');
159
            $commands = new Commands($this->container);
160
            $ret = $commands->generateEntity($wbFile, $bundlePath);
161
            (new LockSystem($this->container))->lockFile(false);
162
            return new Response($ret['message']);
163
        }
164
    }
165
166
    /* ENTITIES */
167
168
    public function generateEntityClassAction(Request $request)
169
    {
170
        if ((new LockSystem($this->container))->isLockedFile()) {
171
            return (new LockSystem($this->container))->lockedFunctionMessage();
172
        } else {
173
            (new LockSystem($this->container))->lockFile(true);
174
            $bundlePath = $request->get('bundle');
175
            $commands = new Commands($this->container);
176
            $ret = $commands->generateEntityClass($bundlePath);
177
            (new LockSystem($this->container))->lockFile(false);
178
179
            return new Response($ret['message']);
180
        }
181
    }
182
183
    /* BUNDLE */
184
185
    public function generateBundleAction(Request $request)
186
    {
187
        $this->apppaths = new ProjectPath($this->container);
188
        if ((new LockSystem($this->container))->isLockedFile()) {
189
            return (new LockSystem($this->container))->lockedFunctionMessage();
190
        } else {
191
            (new LockSystem($this->container))->lockFile(true);
192
            $commands = new Commands($this->container);
193
            $bundleName = $request->get('bundlename');
194
            $result = $commands->generateBundle($bundleName);
195
            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...
196
                //$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...
197
                //$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...
198
                //$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...
199
            }
200
            (new LockSystem($this->container))->lockFile(false);
201
            //Uso exit perchè la render avendo creato un nuovo bundle schianta perchè non è caricato nel kernel il nuovo bundle ancora
202
            //exit;
203
            $twigparms = array('errcode' => $result['errcode'], 'command' => $result['command'], 'message' => $result['message']);
204
205
            //$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...
206
            //$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...
207
            //$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...
208
209
            return $this->render('PannelloAmministrazioneBundle:PannelloAmministrazione:outputcommand.html.twig', $twigparms);
210
        }
211
    }
212
213
    /* 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...
214
215
    public function getVcsAction()
216
    {
217
        set_time_limit(0);
218
        $this->apppaths = new ProjectPath($this->container);
219
        if ((new LockSystem($this->container))->isLockedFile()) {
220
            return (new LockSystem($this->container))->lockedFunctionMessage();
221
        } else {
222
            (new LockSystem($this->container))->lockFile(true);
223
            $commands = new Commands($this->container);
224
            $result = $commands->getVcs();
225
            (new LockSystem($this->container))->lockFile(false);
226
            if ($result['errcode'] < 0) {
227
                $responseout = '<pre>Errore nel comando: <i style = "color: white;">' . $result['command'] . '</i>'
228
                        . '<br/><i style = "color: red;">' . nl2br($result['errmsg']) . '</i></pre>';
229
            } else {
230
                $responseout = '<pre>Eseguito comando: <i style = "color: white;">' . $result['command'] . '</i><br/>' .
231
                        nl2br($result['errmsg']) . '</pre>';
232
            }
233
234
            return new Response($responseout);
235
        }
236
    }
237
238
    /* CLEAR CACHE */
239
240
    /**
241
     * Suppress PMD warnings per exit.
242
     *
243
     * @SuppressWarnings(PHPMD)
244
     */
245
    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...
246
    {
247
        set_time_limit(0);
248
        if ((new LockSystem($this->container))->isLockedFile()) {
249
            return (new LockSystem($this->container))->lockedFunctionMessage();
250
        } else {
251
            (new LockSystem($this->container))->lockFile(true);
252
            $commands = new Commands($this->container);
253
            $result = $commands->clearcache();
254
255
            (new LockSystem($this->container))->lockFile(false);
256
257
            /* Uso exit perchè new response avendo cancellato la cache schianta non avendo più a disposizione i file */
258
            //return $commanddev . '<br/>' . $cmdoutputdev . '<br/><br/>' . $commandprod . '<br/>' . $cmdoutputprod;
259
            //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...
260
            exit(nl2br($result));
261
        }
262
    }
263
264
    /* CLEAR CACHE */
265
266
    public function symfonyCommandAction(Request $request)
267
    {
268
        set_time_limit(0);
269
        $comando = $request->get('symfonycommand');
270
        if ((new LockSystem($this->container))->isLockedFile()) {
271
            return (new LockSystem($this->container))->lockedFunctionMessage();
272
        } else {
273
            (new LockSystem($this->container))->lockFile(true);
274
            $this->apppaths = new ProjectPath($this->container);
275
            $pammutils = new PannelloAmministrazioneUtils($this->container);
276
            $phpPath = OsFunctions::getPHPExecutableFromPath();
277
            $result = $pammutils->runCommand($phpPath . ' ' . $this->apppaths->getConsole() . ' ' . $comando);
278
279
            (new LockSystem($this->container))->lockFile(false);
280
            if ($result['errcode'] < 0) {
281
                $responseout = 'Errore nel comando: <i style = "color: white;">' .
282
                        str_replace(';', '<br/>', str_replace('&&', '<br/>', $comando)) .
283
                        '</i><br/><i style = "color: red;">' . nl2br($result['errmsg']) . '</i>';
284
285
                return new Response($responseout);
286
            }
287
            $responseout = '<pre>Eseguito comando:<br/><br/><i style = "color: white;">' .
288
                    str_replace(';', '<br/>', str_replace('&&', '<br/>', $comando)) . '</i><br/><br/>' .
289
                    str_replace("\n", '<br/>', $result['errmsg']) . '</pre>';
290
291
            return new Response($responseout);
292
        }
293
    }
294
295
    /**
296
     * Suppress PMD warnings per exit.
297
     *
298
     * @SuppressWarnings(PHPMD)
299
     */
300
    public function unixCommandAction(Request $request)
301
    {
302
        set_time_limit(0);
303
        $pammutils = new PannelloAmministrazioneUtils($this->container);
304
        $command = $request->get('unixcommand');
305
        if (!OsFunctions::isWindows()) {
306
            $lockdelcmd = 'rm -rf ';
307
        } else {
308
            $lockdelcmd = 'del ';
309
        }
310
        //Se viene lanciato il comando per cancellare il file di lock su bypassa tutto e si lancia
311
        $filelock = str_replace('\\', '\\\\', (new LockSystem($this->container))->getFileLock());
312
        if (str_replace('\\\\', '/', $command) == str_replace('\\\\', '\\', $lockdelcmd . $filelock)) {
313
            $fs = new Filesystem();
314
            if ((!($fs->exists($filelock)))) {
315
                return new Response('Non esiste il file di lock: <i style = "color: white;">' . $filelock . '</i><br/>');
316
            } else {
317
                $result = $pammutils->runCommand($command);
318
319
                // eseguito deopo la fine del comando
320
                if ($result['errmsg'] < 0) {
321
                    $responseout = 'Errore nel comando: <i style = "color: white;">' .
322
                            str_replace(';', '<br/>', str_replace('&&', '<br/>', $command)) .
323
                            '</i><br/><i style = "color: red;">' . str_replace("\n", '<br/>', $result['errmsg']) . '</i>';
324
325
                    exit(nl2br($responseout));
326
                }
327
328
                return new Response('File di lock cancellato');
329
            }
330
        }
331
332
        if ((new LockSystem($this->container))->isLockedFile()) {
333
            return (new LockSystem($this->container))->lockedFunctionMessage();
334
        } else {
335
            (new LockSystem($this->container))->lockFile(true);
336
            //$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...
337
            $result = $pammutils->runCommand($command);
338
339
            (new LockSystem($this->container))->lockFile(false);
340
            // eseguito deopo la fine del comando
341
            if ($result['errcode'] < 0) {
342
                $errmsg = 'Errore nel comando: <i style = "color: white;">' .
343
                        str_replace(';', '<br/>', str_replace('&&', '<br/>', $command)) .
344
                        '</i><br/><i style = "color: red;">' . nl2br($result['errmsg']) . '</i>';
345
346
                //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...
347
                exit(nl2br($errmsg));
348
                //Uso exit perchè new response avendo cancellato la cache schianta non avendo più a disposizione i file
349
                //return;
350
                /* 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...
351
                 * $command . '</i><br/><i style = "color: red;">' . str_replace("\n", '<br/>', $process->getErrorOutput()) . '</i>'); */
352
            }
353
            $msgok = '<pre>Eseguito comando:<br/><i style = "color: white;"><br/>' .
354
                    str_replace(';', '<br/>', str_replace('&&', '<br/>', $command)) . '</i><br/>' .
355
                    nl2br($result['errmsg']) . '</pre>';
356
            //Uso exit perchè new response avendo cancellato la cache schianta non avendo più a disposizione i file
357
            //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...
358
            exit(nl2br($msgok));
359
            //return;
360
            /* 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...
361
             * '</i><br/>' . str_replace("\n", "<br/>", $process->getOutput()) . "</pre>"); */
362
        }
363
    }
364
365
    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...
366
    {
367
        set_time_limit(0);
368
        $this->apppaths = new ProjectPath($this->container);
369
        if ((new LockSystem($this->container))->isLockedFile()) {
370
            return (new LockSystem($this->container))->lockedFunctionMessage();
371
        } else {
372
            if (!OsFunctions::isWindows()) {
373
                (new LockSystem($this->container))->lockFile(true);
374
                //$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...
375
                $sepchr = OsFunctions::getSeparator();
376
                $phpPath = OsFunctions::getPHPExecutableFromPath();
377
378
                // Questo codice per versioni che usano un symfony 2 o 3
379
                if (version_compare(\Symfony\Component\HttpKernel\Kernel::VERSION, '3.0') >= 0) {
380
                    $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr .
381
                            $phpPath . ' ' . 'vendor' . DIRECTORY_SEPARATOR . 'bin' . DIRECTORY_SEPARATOR . 'phpunit';
382
                } else {
383
                    $command = 'cd ' . $this->apppaths->getRootPath() . $sepchr .
384
                            $phpPath . ' ' . 'bin' . DIRECTORY_SEPARATOR . 'phpunit -c app';
385
                }
386
387
                $process = new Process($command);
388
                $process->run();
389
390
                (new LockSystem($this->container))->lockFile(false);
391
                // eseguito deopo la fine del comando
392
                /* 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...
393
                  return new Response('Errore nel comando: <i style = "color: white;">' .
394
                 * $command . '</i><br/><i style = "color: red;">' . str_replace("\n",
395
                 * '<br/>', $process->getErrorOutput()) . '</i>');
396
                  } */
397
                $responseout = '<pre>Eseguito comando: <i style = "color: white;">' . $command . '</i><br/>' .
398
                        str_replace("\n", '<br/>', $process->getOutput()) . '</pre>';
399
400
                return new Response($responseout);
401
            } else {
402
                return new Response('Non previsto in ambiente windows!');
403
            }
404
        }
405
    }
406
}
407