File: remove-comments-in-switch.php

package info (click to toggle)
php-nesbot-carbon 2.73.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 19,884 kB
  • sloc: php: 158,586; xml: 99; makefile: 33; sh: 14
file content (43 lines) | stat: -rw-r--r-- 1,033 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

declare(strict_types=1);

/**
 * This file is part of the Carbon package.
 *
 * (c) Brian Nesbitt <brian@nesbot.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

$files = [
    __DIR__.'/../src/Carbon/Traits/Date.php',
    __DIR__.'/../src/Carbon/Traits/Units.php',
    __DIR__.'/../src/Carbon/Lang/fr.php',
];

$comments = [
    '// @property',
    '// @call ',
    '// Words with feminine grammatical gender: semaine',
];

foreach ($files as $file) {
    $contents = str_replace("\r", '', file_get_contents($file));
    $newContents = implode("\n", array_filter(explode("\n", $contents), static function ($line) use ($comments) {
        $code = trim($line);

        foreach ($comments as $comment) {
            if (str_starts_with($code, $comment)) {
                return false;
            }
        }

        return true;
    }));

    if ($newContents !== $contents) {
        file_put_contents($file, $newContents);
    }
}