Passed
Push — master ( 0ce938...d2fa5d )
by Michiel
11:37
created

SassTask::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 *
19
 * @category Tasks
20
 * @package  phing.tasks.ext
21
 * @author   Paul Stuart <[email protected]>
22
 * @author   Ken Guest <[email protected]>
23
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
24
 */
25
26
/**
27
 * Executes Sass for a particular fileset.
28
 *
29
 * If the sass executable is not available, but scssphp is, then use that instead.
30
 *
31
 * @category Tasks
32
 * @package  phing.tasks.ext
33
 * @author   Paul Stuart <[email protected]>
34
 * @author   Ken Guest <[email protected]>
35
 * @license  LGPL (see http://www.gnu.org/licenses/lgpl.html)
36
 * @link     SassTask.php
37
 */
38
class SassTask extends Task
39
{
40
41
    /**
42
     * Style to generate to.
43
     *
44
     * @var string
45
     */
46
    protected $style = 'nested';
47
48
    /**
49
     * Stack trace on error.
50
     *
51
     * @var bool
52
     */
53
    protected $trace = false;
54
55
    /**
56
     * Unix-style newlines?
57
     *
58
     * @var bool
59
     */
60
    protected $unixnewlines = true;
61
62
    /**
63
     * Encoding
64
     *
65
     * @var string
66
     */
67
    protected $encoding = 'utf-8';
68
69
    /**
70
     * SASS import path.
71
     *
72
     * @var string
73
     */
74
    protected $loadPath = '';
75
76
    /**
77
     * Whether to just check syntax
78
     *
79
     * @var bool
80
     */
81
    protected $check = false;
82
83
    /**
84
     * Whether to use the sass command line tool.
85
     *
86
     * @var bool
87
     */
88
    protected $useSass = true;
89
90
    /**
91
     * Whether to use the scssphp compiler, if available.
92
     *
93
     * @var bool
94
     */
95
    protected $useScssphp = true;
96
97
    /**
98
     * Input filename if only processing one file is required.
99
     *
100
     * @var string|null
101
     */
102
    protected $file = null;
103
104
    /**
105
     * Output filename
106
     *
107
     * @var string|null
108
     */
109
    protected $output = null;
110
111
    /**
112
     * Contains the path info of our file to allow us to parse.
113
     *
114
     * @var array
115
     */
116
    protected $pathInfo = null;
117
118
    /**
119
     * The Sass executable.
120
     *
121
     * @var string
122
     */
123
    protected $executable = 'sass';
124
125
    /**
126
     * The ext type we are looking for when Verifyext is set to true.
127
     *
128
     * More than likely should be "scss" or "sass".
129
     *
130
     * @var string
131
     */
132
    protected $extfilter = '';
133
134
    /**
135
     * This flag means 'note errors to the output, but keep going'
136
     *
137
     * @var bool
138
     */
139
    protected $failonerror = true;
140
141
    /**
142
     * The fileset we will be running Sass on.
143
     *
144
     * @var array
145
     */
146
    protected $filesets = [];
147
148
    /**
149
     * Additional flags to pass to sass.
150
     *
151
     * @var string
152
     */
153
    protected $flags = '';
154
155
    /**
156
     * Indicates if we want to keep the directory structure of the files.
157
     *
158
     * @var bool
159
     */
160
    protected $keepsubdirectories = true;
161
162
    /**
163
     * When true we will remove the current file ext.
164
     *
165
     * @var bool
166
     */
167
    protected $removeoldext = true;
168
169
    /**
170
     * The new ext our files will have.
171
     *
172
     * @var string
173
     */
174
    protected $newext = 'css';
175
    /**
176
     * The path to send our output files to.
177
     *
178
     * If not defined they will be created in the same directory the
179
     * input is from.
180
     *
181
     * @var string
182
     */
183
    protected $outputpath = '';
184
185
    /**
186
     * @var bool
187
     */
188
    protected $force;
189
190
    /**
191
     * @var bool
192
     */
193
    protected $lineNumbers = false;
194
195
    /**
196
     * @var bool
197
     */
198
    protected $noCache;
199
200
    /**
201
     * Set input file (For example style.scss)
202
     *
203
     * Synonym for @see setFile
204
     *
205
     * @param string $file Filename
206
     *
207
     * @return void
208
     */
209
    public function setInput($file)
210
    {
211
        $this->setFile($file);
212
    }
213
214
    /**
215
     * Set name of output file.
216
     *
217
     * @param string $file Filename of [css] to output.
218
     *
219
     * @return void
220
     */
221
    public function setOutput($file)
222
    {
223
        $this->output = $file;
224
    }
225
226
    /**
227
     * Sets the failonerror flag. Default: true
228
     *
229
     * @param string $failonerror Jenkins style boolean value
230
     *
231
     * @access public
232
     * @return void
233
     */
234
    public function setFailonerror($failonerror)
235
    {
236
        $this->failonerror = StringHelper::booleanValue($failonerror);
237
    }
238
239
    /**
240
     * Sets the executable to use for sass. Default: sass
241
     *
242
     * The default assumes sass is in your path. If not you can provide the full
243
     * path to sass.
244
     *
245
     * @param string $executable Name of executable, optionally including full path
246
     *
247
     * @return void
248
     */
249 1
    public function setExecutable(string $executable): void
250
    {
251 1
        $this->executable = $executable;
252 1
    }
253
254
    /**
255
     * Return name/path of sass executable.
256
     */
257 4
    public function getExecutable(): string
258
    {
259 4
        return $this->executable;
260
    }
261
262
    /**
263
     * Sets the extfilter. Default: <none>
264
     *
265
     * This will filter the fileset to only process files that match
266
     * this extension. This could also be done with the fileset.
267
     *
268
     * @param string $extfilter Extension to filter for.
269
     *
270
     * @access public
271
     * @return void
272
     */
273
    public function setExtfilter($extfilter)
274
    {
275
        $this->extfilter = trim($extfilter, ' .');
276
    }
277
278
    /**
279
     * Return extfilter setting.
280
     *
281
     * @return string
282
     */
283 1
    public function getExtfilter()
284
    {
285 1
        return $this->extfilter;
286
    }
287
288
    /**
289
     * Additional flags to pass to sass.
290
     *
291
     * Command will be:
292
     * sass {$flags} {$inputfile} {$outputfile}
293
     *
294
     * @param string $flags Flags to pass
295
     *
296
     * @return void
297
     */
298
    public function setFlags(string $flags): void
299
    {
300
        $this->flags = trim($flags);
301
    }
302
303
    /**
304
     * Return flags to be used when running the sass executable.
305
     */
306 6
    public function getFlags(): string
307
    {
308 6
        return trim($this->flags);
309
    }
310
311
    /**
312
     * Sets the removeoldext flag. Default: true
313
     *
314
     * This will cause us to strip the existing extension off the output
315
     * file.
316
     *
317
     * @param string $removeoldext Jenkins style boolean value
318
     *
319
     * @access public
320
     * @return void
321
     */
322
    public function setRemoveoldext($removeoldext)
323
    {
324
        $this->removeoldext = StringHelper::booleanValue($removeoldext);
325
    }
326
327
    /**
328
     * Return removeoldext value (true/false)
329
     *
330
     * @return bool
331
     */
332 1
    public function getRemoveoldext()
333
    {
334 1
        return $this->removeoldext;
335
    }
336
337
    /**
338
     * Set default encoding
339
     *
340
     * @param string $encoding Default encoding to use.
341
     *
342
     * @return void
343
     */
344
    public function setEncoding($encoding)
345
    {
346
        $encoding = trim($encoding);
347
        if ($encoding !== '') {
348
            $this->flags .= " --default-encoding $encoding";
349
        } else {
350
            $this->flags = str_replace(
351
                ' --default-encoding ' . $this->encoding,
352
                '',
353
                $this->flags
354
            );
355
        }
356
        $this->encoding = $encoding;
357
    }
358
359
    /**
360
     * Return the output encoding.
361
     *
362
     * @return string
363
     */
364 2
    public function getEncoding()
365
    {
366 2
        return $this->encoding;
367
    }
368
369
    /**
370
     * Sets the newext value. Default: css
371
     *
372
     * This is the extension we will add on to the output file regardless
373
     * of if we remove the old one or not.
374
     *
375
     * @param string $newext New extension to use, e.g. css
376
     *
377
     * @access public
378
     * @return void
379
     */
380
    public function setNewext($newext)
381
    {
382
        $this->newext = trim($newext, ' .');
383
    }
384
385
    /**
386
     * Return extension added to output files.
387
     *
388
     * @return string
389
     */
390 1
    public function getNewext()
391
    {
392 1
        return $this->newext;
393
    }
394
395
    /**
396
     * Sets the outputpath value. Default: <none>
397
     *
398
     * This will force the output path to be something other than
399
     * the path of the fileset used.
400
     *
401
     * @param string $outputpath Path name
402
     *
403
     * @access public
404
     * @return void
405
     */
406 1
    public function setOutputpath($outputpath)
407
    {
408 1
        $this->outputpath = rtrim(trim($outputpath), DIRECTORY_SEPARATOR);
409 1
    }
410
411
    /**
412
     * Return the outputpath value.
413
     *
414
     * @return string
415
     */
416 1
    public function getOutputpath()
417
    {
418 1
        return $this->outputpath;
419
    }
420
421
    /**
422
     * Sets the keepsubdirectories value. Default: true
423
     *
424
     * When set to true we will keep the directory structure. So any input
425
     * files in subdirectories will have their output file in that same
426
     * sub-directory. If false, all output files will be put in the path
427
     * defined by outputpath or in the directory top directory of the fileset.
428
     *
429
     * @param bool $keepsubdirectories Jenkins style boolean
430
     *
431
     * @access public
432
     * @return void
433
     */
434
    public function setKeepsubdirectories($keepsubdirectories)
435
    {
436
        $this->keepsubdirectories = StringHelper::booleanValue($keepsubdirectories);
437
    }
438
439
    /**
440
     * Return keepsubdirectories value.
441
     *
442
     * @return bool
443
     */
444 1
    public function getKeepsubdirectories()
445
    {
446 1
        return $this->keepsubdirectories;
447
    }
448
449
    /**
450
     * Nested creator, creates a FileSet for this task
451
     *
452
     * @return FileSet The created fileset object
453
     */
454 3
    public function createFileSet()
455
    {
456 3
        $num = array_push($this->filesets, new FileSet());
457 3
        return $this->filesets[$num - 1];
458
    }
459
460
    /**
461
     * Whether to just check syntax.
462
     *
463
     * @param string $value Jenkins style boolean value
464
     *
465
     * @return void
466
     */
467
    public function setCheck($value)
468
    {
469
        $check = StringHelper::booleanValue($value);
470
        $this->check = $check;
471
        if ($check) {
472
            $this->flags .= ' --check ';
473
        } else {
474
            $this->flags = str_replace(' --check ', '', $this->flags);
475
        }
476
    }
477
478
    /**
479
     * Indicate if just a syntax check is required.
480
     *
481
     * @return boolean
482
     */
483 1
    public function getCheck()
484
    {
485 1
        return $this->check;
486
    }
487
488
    /**
489
     * Set style to compact
490
     *
491
     * @param string $value Jenkins style boolean value
492
     *
493
     * @return void
494
     */
495 1
    public function setCompact($value)
496
    {
497 1
        $compress = StringHelper::booleanValue($value);
498 1
        if ($compress) {
499 1
            $this->flags = str_replace(' --style ' . $this->style, '', $this->flags);
500 1
            $this->flags .= ' --style compact';
501 1
            $this->style = 'compact';
502
        }
503 1
    }
504
505
    /**
506
     * Indicate whether style is set to 'coompact'.
507
     *
508
     * @return bool
509
     * @see    setCompact
510
     */
511 5
    public function getCompact()
512
    {
513 5
        return $this->style === 'compact';
514
    }
515
516
    /**
517
     * Set style to compressed
518
     *
519
     * @param string $value Jenkins style boolean value
520
     *
521
     * @return void
522
     */
523 1
    public function setCompressed($value)
524
    {
525 1
        $compress = StringHelper::booleanValue($value);
526 1
        if ($compress) {
527 1
            $this->flags = str_replace(' --style ' . $this->style, '', $this->flags);
528 1
            $this->flags .= ' --style compressed';
529 1
            $this->style = 'compressed';
530
        }
531 1
    }
532
533
    /**
534
     * Indicate whether style is set to 'compressed'.
535
     *
536
     * @return bool
537
     * @see    setCompressed
538
     */
539 5
    public function getCompressed()
540
    {
541 5
        return $this->style === 'compressed';
542
    }
543
544
    /**
545
     * Set style to crunched. Supported by scssphp only.
546
     *
547
     * @param string $value Jenkins style boolean value
548
     *
549
     * @return void
550
     */
551
    public function setCrunched($value)
552
    {
553
        $compress = StringHelper::booleanValue($value);
554
        if ($compress) {
555
            $this->style = 'crunched';
556
        }
557
    }
558
559
    /**
560
     * Indicate whether style is set to 'crunched'.
561
     *
562
     * @return bool
563
     * @see    setCrunched
564
     */
565 5
    public function getCrunched()
566
    {
567 5
        return $this->style === 'crunched';
568
    }
569
570
    /**
571
     * Set style to expanded
572
     *
573
     * @param string $value Jenkins style boolean value
574
     *
575
     * @return void
576
     */
577
    public function setExpand($value)
578
    {
579
        $expand = StringHelper::booleanValue($value);
580
        if ($expand) {
581
            $this->flags = str_replace(' --style ' . $this->style, '', $this->flags);
582
            $this->flags .= ' --style expanded';
583
            $this->style = 'expanded';
584
        }
585
    }
586
587
    /**
588
     * Indicate whether style is set to 'expanded'.
589
     *
590
     * @return bool
591
     * @see    setExpand
592
     */
593 5
    public function getExpand()
594
    {
595 5
        return $this->style === 'expanded';
596
    }
597
598
    /**
599
     * Set style to nested
600
     *
601
     * @param string $value Jenkins style boolean value
602
     *
603
     * @return void
604
     */
605
    public function setNested($value)
606
    {
607
        $nested = StringHelper::booleanValue($value);
608
        if ($nested) {
609
            $this->flags = str_replace(' --style ' . $this->style, '', $this->flags);
610
            $this->flags .= ' --style nested';
611
            $this->style = 'nested';
612
        }
613
    }
614
615
    /**
616
     * Indicate whether style is set to 'nested'.
617
     *
618
     * @return bool
619
     * @see    setNested
620
     */
621 5
    public function getNested()
622
    {
623 5
        return $this->style === 'nested';
624
    }
625
626
    /**
627
     * Whether to force recompiled when --update is used.
628
     *
629
     * @param string $value Jenkins style boolean value
630
     *
631
     * @return void
632
     */
633
    public function setForce($value)
634
    {
635
        $force = StringHelper::booleanValue($value);
636
        $this->force = $force;
637
        if ($force) {
638
            $this->flags .= ' --force ';
639
        } else {
640
            $this->flags = str_replace(' --force ', '', $this->flags);
641
        }
642
    }
643
644
    /**
645
     * Return force value.
646
     *
647
     * @return bool
648
     */
649
    public function getForce()
650
    {
651
        return $this->force;
652
    }
653
654
    /**
655
     * Whether to cache parsed sass files.
656
     *
657
     * @param string $value Jenkins style boolean value
658
     *
659
     * @return void
660
     */
661
    public function setNoCache($value)
662
    {
663
        $noCache = StringHelper::booleanValue($value);
664
        $this->noCache = $noCache;
665
        if ($noCache) {
666
            $this->flags .= ' --no-cache ';
667
        } else {
668
            $this->flags = str_replace(' --no-cache ', '', $this->flags);
669
        }
670
    }
671
672
    /**
673
     * Return noCache value.
674
     *
675
     * @return bool
676
     */
677
    public function getNoCache()
678
    {
679
        return $this->noCache;
680
    }
681
682
    /**
683
     * Specify SASS import path
684
     *
685
     * @param string $path Import path
686
     *
687
     * @return void
688
     */
689
    public function setPath(string $path): void
690
    {
691
        $this->flags .= " --load-path $path ";
692
        $this->loadPath = $path;
693
    }
694
695
    /**
696
     * Return the SASS import path.
697
     */
698 2
    public function getPath(): string
699
    {
700 2
        return $this->loadPath;
701
    }
702
703
    /**
704
     * Set output style.
705
     *
706
     * @param string $style nested|compact|compressed|expanded|crunched
707
     *
708
     * @return void
709
     */
710 6
    public function setStyle(string $style): void
711
    {
712 6
        $style = strtolower($style);
713 6
        switch ($style) {
714 6
            case 'nested':
715 6
            case 'compact':
716 6
            case 'compressed':
717 6
            case 'expanded':
718 6
            case 'crunched':
719 4
                $this->flags = str_replace(" --style $this->style", '', $this->flags);
720 4
                $this->style = $style;
721 4
                $this->flags .= " --style $style ";
722 4
                break;
723
            default:
724 2
                $this->log("Style $style ignored", Project::MSG_INFO);
725
        }
726 6
    }
727
728
    /**
729
     * Return style used for generating output.
730
     */
731 6
    public function getStyle(): string
732
    {
733 6
        return $this->style;
734
    }
735
736
    /**
737
     * Set trace option.
738
     *
739
     * IE: Whether to output a stack trace on error.
740
     *
741
     * @param string $trace Jenkins style boolean value
742
     *
743
     * @return void
744
     */
745
    public function setTrace($trace)
746
    {
747
        $this->trace = StringHelper::booleanValue($trace);
748
        if ($this->trace) {
749
            $this->flags .= ' --trace ';
750
        } else {
751
            $this->flags = str_replace(' --trace ', '', $this->flags);
752
        }
753
    }
754
755
    /**
756
     * Return trace option.
757
     *
758
     * @return bool
759
     */
760 1
    public function getTrace()
761
    {
762 1
        return $this->trace;
763
    }
764
765
    /**
766
     * Whether to use unix-style newlines.
767
     *
768
     * @param string $newlines Jenkins style boolean value
769
     *
770
     * @return void
771
     */
772
    public function setUnixnewlines($newlines)
773
    {
774
        $unixnewlines = StringHelper::booleanValue($newlines);
775
        $this->unixnewlines = $unixnewlines;
776
        if ($unixnewlines) {
777
            $this->flags .= ' --unix-newlines ';
778
        } else {
779
            $this->flags = str_replace(' --unix-newlines ', '', $this->flags);
780
        }
781
    }
782
783
    /**
784
     * Return unix-newlines setting
785
     *
786
     * @return bool
787
     */
788 1
    public function getUnixnewlines()
789
    {
790 1
        return $this->unixnewlines;
791
    }
792
793
    /**
794
     * Whether to identify source-file and line number for generated CSS.
795
     *
796
     * @param string $lineNumbers Jenkins style boolean value
797
     */
798
    public function setLineNumbers(string $lineNumbers): void
799
    {
800
        $lineNumbers = StringHelper::booleanValue($lineNumbers);
801
        $this->lineNumbers = $lineNumbers;
802
        if ($lineNumbers) {
803
            $this->flags .= ' --line-numbers ';
804
        } else {
805
            $this->flags = str_replace(' --line-numbers ', '', $this->flags);
806
        }
807
    }
808
809
    /**
810
     * Return line-numbers setting.
811
     */
812 1
    public function getLineNumbers(): bool
813
    {
814 1
        return $this->lineNumbers;
815
    }
816
817
    /**
818
     * Whether to use the 'sass' command line tool.
819
     *
820
     * @param string $value Jenkins style boolean value.
821
     *
822
     * @return void
823
     * @link   http://sass-lang.com/install
824
     */
825 8
    public function setUseSass($value)
826
    {
827 8
        $this->useSass = StringHelper::booleanValue($value);
828 8
    }
829
830
    /**
831
     * Get useSass property value
832
     *
833
     * @return bool
834
     */
835 7
    public function getUseSass(): bool
836
    {
837 7
        return $this->useSass;
838
    }
839
840
    /**
841
     * Whether to use the scssphp compiler.
842
     *
843
     * @param string $value Jenkins style boolean value.
844
     *
845
     * @return void
846
     * @link   https://scssphp.github.io/scssphp/
847
     */
848 8
    public function setUseScssphp($value)
849
    {
850 8
        $this->useScssphp = StringHelper::booleanValue($value);
851 8
    }
852
853
    /**
854
     * Whether to use the Scss php library
855
     *
856
     * @return bool
857
     */
858 7
    public function getUseScssPhp(): bool
859
    {
860 7
        return $this->useScssphp;
861
    }
862
863
    /**
864
     * Set single filename to compile from scss to css.
865
     *
866
     * @param string $file Single filename to compile.
867
     *
868
     * @return void
869
     */
870
    public function setFile($file)
871
    {
872
        $this->file = $file;
873
    }
874
875
    /**
876
     * Our main execution of the task.
877
     *
878
     * @throws BuildException
879
     * @throws Exception
880
     *
881
     * @access public
882
     * @return void
883
     */
884 4
    public function main()
885
    {
886 4
        if ($this->useSass) {
887
            if (strlen($this->executable) < 0) {
888
                throw new BuildException("'executable' must be defined.");
889
            }
890
        }
891
892 4
        if (empty($this->filesets) && $this->file === null) {
893 1
            throw new BuildException(
894 1
                "Missing either a nested fileset or attribute 'file'"
895
            );
896
        }
897
898
        try {
899 3
            $compiler = (new SassTaskCompilerFactory(FileSystem::getFileSystem()))->prepareCompiler($this);
900 2
        } catch (BuildException $exception) {
901 2
            if ($this->failonerror) {
902 2
                throw $exception;
903
            }
904
            $this->log($exception->getMessage());
905
            return;
906
        }
907
908 1
        if (count($this->filesets) > 0) {
909 1
            $this->processFilesets($compiler);
910
        } elseif ($this->file !== null) {
911
            $this->processFile($compiler);
912
        }
913 1
    }
914
915
    /**
916
     * Compile a specified file.
917
     *
918
     * If output file is not specified, but outputpath is, place output in
919
     * that directory. If neither is specified, place .css file in the
920
     * directory that the input file is in.
921
     *
922
     * @param SassTaskCompiler $compiler Compiler to use for processing fileset
923
     *
924
     * @return void
925
     */
926
    public function processFile(SassTaskCompiler $compiler)
927
    {
928
        $this->log("Process file", Project::MSG_INFO);
929
        if (null === $this->output) {
930
            $specifiedOutputPath = (strlen($this->outputpath) > 0);
931
            if ($specifiedOutputPath === false) {
932
                $info = pathinfo($this->file);
933
                $path = $info['dirname'];
934
                $this->outputpath = $path;
935
            } else {
936
                $path = $this->outputpath;
937
            }
938
            $output = $path . DIRECTORY_SEPARATOR . $info['filename'];
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $info does not seem to be defined for all execution paths leading up to this point.
Loading history...
939
            if (!$this->removeoldext) {
940
                $output .= '.' . $this->pathInfo['extension'];
941
            }
942
943
            if (strlen($this->newext) > 0) {
944
                $output .= '.' . $this->newext;
945
            }
946
            $this->output = $output;
947
        } else {
948
            $output = $this->output;
949
        }
950
951
        $compiler->compile($this->file, $output, $this->failonerror);
0 ignored issues
show
Bug introduced by
It seems like $this->file can also be of type null; however, parameter $inputFilePath of SassTaskCompiler::compile() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

951
        $compiler->compile(/** @scrutinizer ignore-type */ $this->file, $output, $this->failonerror);
Loading history...
952
    }
953
954
    /**
955
     * Process filesets - compiling/generating css files as required.
956
     *
957
     * @param SassTaskCompiler $compiler Compiler to use for processing fileset
958
     *
959
     * @return void
960
     */
961 1
    public function processFilesets(SassTaskCompiler $compiler): void
962
    {
963 1
        foreach ($this->filesets as $fs) {
964 1
            $ds = $fs->getDirectoryScanner($this->project);
965 1
            $files = $ds->getIncludedFiles();
966 1
            $dir = $fs->getDir($this->project)->getPath();
967
968
            // If output path isn't defined then set it to the path of our fileset.
969 1
            $specifiedOutputPath = (strlen($this->outputpath) > 0);
970 1
            if ($specifiedOutputPath === false) {
971
                $this->outputpath = $dir;
972
            }
973
974 1
            foreach ($files as $file) {
975 1
                $fullFilePath = $dir . DIRECTORY_SEPARATOR . $file;
976 1
                $this->pathInfo = pathinfo($file);
977
978 1
                $run = true;
979 1
                switch (strtolower($this->pathInfo['extension'])) {
980 1
                    case 'scss':
981
                    case 'sass':
982 1
                        break;
983
                    default:
984
                        $this->log('Ignoring ' . $file, Project::MSG_DEBUG);
985
                        $run = false;
986
                }
987
988
                if (
989 1
                    $run
990 1
                    && ($this->extfilter === ''
991
                        || $this->extfilter === $this->pathInfo['extension'])
992
                ) {
993 1
                    $outputFile = $this->buildOutputFilePath();
994 1
                    $compiler->compile($fullFilePath, $outputFile, $this->failonerror);
995
                }
996
            }
997
        }
998 1
    }
999
1000
    /**
1001
     * Builds the full path to the output file based on our settings.
1002
     *
1003
     * @return string
1004
     *
1005
     * @access protected
1006
     */
1007 1
    protected function buildOutputFilePath()
1008
    {
1009 1
        $outputFile = $this->outputpath . DIRECTORY_SEPARATOR;
1010
1011 1
        $subpath = trim($this->pathInfo['dirname'], ' .');
1012
1013 1
        if ($this->keepsubdirectories === true && strlen($subpath) > 0) {
1014
            $outputFile .= $subpath . DIRECTORY_SEPARATOR;
1015
        }
1016
1017 1
        $outputFile .= $this->pathInfo['filename'];
1018
1019 1
        if (!$this->removeoldext) {
1020
            $outputFile .= '.' . $this->pathInfo['extension'];
1021
        }
1022
1023 1
        if (strlen($this->newext) > 0) {
1024 1
            $outputFile .= '.' . $this->newext;
1025
        }
1026
1027 1
        return $outputFile;
1028
    }
1029
}
1030