Skip to content

Commit 9a163d9

Browse files
committed
edited the rule for mktime
1 parent 9437a75 commit 9a163d9

9 files changed

+125
-125
lines changed

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
]
1212
},
1313
"files": [
14-
"generated/apache.php",
1514
"deprecated/apc.php",
15+
"deprecated/libevent.php",
16+
"deprecated/mssql.php",
17+
"deprecated/stats.php",
18+
"lib/special_cases.php",
19+
"generated/apache.php",
1620
"generated/apcu.php",
1721
"generated/array.php",
1822
"generated/bzip2.php",
@@ -44,14 +48,12 @@
4448
"generated/inotify.php",
4549
"generated/json.php",
4650
"generated/ldap.php",
47-
"deprecated/libevent.php",
4851
"generated/libxml.php",
4952
"generated/lzf.php",
5053
"generated/mailparse.php",
5154
"generated/mbstring.php",
5255
"generated/misc.php",
5356
"generated/msql.php",
54-
"deprecated/mssql.php",
5557
"generated/mysql.php",
5658
"generated/mysqli.php",
5759
"generated/mysqlndMs.php",
@@ -83,7 +85,6 @@
8385
"generated/sqlsrv.php",
8486
"generated/ssdeep.php",
8587
"generated/ssh2.php",
86-
"deprecated/stats.php",
8788
"generated/stream.php",
8889
"generated/strings.php",
8990
"generated/swoole.php",
@@ -97,8 +98,7 @@
9798
"generated/yaml.php",
9899
"generated/yaz.php",
99100
"generated/zip.php",
100-
"generated/zlib.php",
101-
"lib/special_cases.php"
101+
"generated/zlib.php"
102102
]
103103
},
104104
"require": {

generator/src/ComposerJsonEditor.php

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,73 @@
88
*/
99
class ComposerJsonEditor
1010
{
11+
private const COMPOSER_FILEPATH = __DIR__.'/../../composer.json';
12+
13+
public static function editComposerFileForDeprecation(string $moduleName): void
14+
{
15+
16+
$composerContent = file_get_contents(self::COMPOSER_FILEPATH);
17+
if ($composerContent === false) {
18+
throw new \RuntimeException('Error while loading composer.json file for edition.');
19+
}
20+
$composerJson = \json_decode($composerContent, true);
21+
$composerJson['autoload']['files'] = self::editFileListForDeprecation($composerJson['autoload']['files'], $moduleName);
22+
23+
$newContent = \json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES);
24+
\file_put_contents(self::COMPOSER_FILEPATH, $newContent);
25+
}
26+
1127
/**
1228
* @param string[] $modules A list of modules
1329
*/
14-
public static function editFiles(array $modules): void
30+
public static function editComposerFileForGeneration(array $modules): void
1531
{
16-
$files = \array_map(function (string $module) {
17-
return 'generated/'.lcfirst($module).'.php';
18-
}, $modules);
19-
$files[] = 'lib/special_cases.php';
20-
$composerContent = file_get_contents(__DIR__.'/../../composer.json');
32+
33+
$composerContent = file_get_contents(self::COMPOSER_FILEPATH);
2134
if ($composerContent === false) {
2235
throw new \RuntimeException('Error while loading composer.json file for edition.');
2336
}
2437
$composerJson = \json_decode($composerContent, true);
25-
$composerJson['autoload']['files'] = $files;
38+
$composerJson['autoload']['files'] = self::editFilesListForGeneration($composerJson['autoload']['files'], $modules);
39+
40+
$newContent = \json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES);
41+
\file_put_contents(self::COMPOSER_FILEPATH, $newContent);
42+
}
43+
44+
45+
46+
47+
/**
48+
* @param string[] $oldFiles
49+
* @param string[] $modules A list of modules
50+
* @return string[]
51+
*/
52+
public static function editFilesListForGeneration(array $oldFiles, array $modules): array
53+
{
54+
$files = array_values(array_filter($oldFiles, function ($file) {
55+
return strpos($file, 'generated/') === false;
56+
}));
57+
foreach ($modules as $module) {
58+
$files[] = 'generated/'.lcfirst($module).'.php';
59+
}
60+
return $files;
61+
}
62+
63+
/**
64+
* @param string[] $fileList
65+
* @return string[]
66+
*/
67+
public static function editFileListForDeprecation(array $fileList, string $moduleName): array
68+
{
69+
$newList = [];
70+
foreach ($fileList as $fileName) {
71+
if ($fileName === "generated/$moduleName.php") {
72+
$newList[] = "deprecated/$moduleName.php";
73+
} else {
74+
$newList[] = $fileName;
75+
}
76+
}
2677

27-
$newContent = json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES);
28-
\file_put_contents(__DIR__.'/../../composer.json', $newContent);
78+
return $newList;
2979
}
3080
}

generator/src/DeprecateCommand.php

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,17 @@ protected function execute(InputInterface $input, OutputInterface $output)
3939
throw new \RuntimeException("Could not move the file.");
4040
}
4141

42-
$exceptionFilePath = self::GENERATE_DIRECTORY.$this->getExceptionFilePath($moduleName);
43-
$moveException = false;
42+
$exceptionFilePath = self::GENERATE_DIRECTORY.self::getExceptionFilePath($moduleName);
4443
if (\file_exists($exceptionFilePath)) {
45-
$moveException = true;
4644
$output->writeln("Move exception file to deprecated");
47-
$success = \rename($exceptionFilePath, self::DEPRECATE_DIRECTORY.$this->getExceptionFilePath($moduleName));
45+
$success = \rename($exceptionFilePath, self::DEPRECATE_DIRECTORY.self::getExceptionFilePath($moduleName));
4846
if (!$success) {
4947
throw new \RuntimeException("Could not move the file.");
5048
}
5149
}
5250

5351
$output->writeln('Editing composer.json');
54-
$this->editComposerFile($moduleName, $moveException);
52+
ComposerJsonEditor::editComposerFileForDeprecation($moduleName);
5553

5654
$generatedListFile = self::GENERATE_DIRECTORY.'functionsList.php';
5755
$deprecatedListFile = self::DEPRECATE_DIRECTORY.'functionsList.php';
@@ -65,39 +63,4 @@ public static function getExceptionFilePath(string $moduleName): string
6563
return "Exceptions/".ucfirst($moduleName)."Exception.php";
6664
}
6765

68-
69-
private function editComposerFile(string $moduleName, bool $moveException): void
70-
{
71-
72-
$composerContent = file_get_contents(__DIR__.'/../../composer.json');
73-
if ($composerContent === false) {
74-
throw new \RuntimeException('Error while loading composer.json file for edition.');
75-
}
76-
$composerJson = \json_decode($composerContent, true);
77-
$composerJson['autoload']['files'] = self::editFileList($composerJson['autoload']['files'], $moduleName);
78-
79-
$newContent = json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES);
80-
\file_put_contents(__DIR__.'/../../composer.json', $newContent);
81-
}
82-
83-
/**
84-
* @param string[] $fileList
85-
* @return string[]
86-
*/
87-
public static function editFileList(array $fileList, string $moduleName): array
88-
{
89-
$newList = [];
90-
foreach ($fileList as $fileName) {
91-
if ($fileName === "generated/$moduleName.php") {
92-
$newList[] = "deprecated/$moduleName.php";
93-
//} else if($fileName === self::GENERATE_DIRECTORY.self::getExceptionFilePath($moduleName)) {
94-
// $newList[] = self::DEPRECATE_DIRECTORY.self::getExceptionFilePath($moduleName);
95-
} else {
96-
$newList[] = $fileName;
97-
}
98-
}
99-
100-
return $newList;
101-
}
102-
10366
}

generator/src/DocPage.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,15 @@ public function detectFalsyFunction(): bool
106106
return true;
107107
}
108108

109+
if (preg_match('/&gd\.return\.identifier;/m', $file)) {
110+
return true;
111+
}
109112
if (preg_match('/&gd\.return\.identifier;/m', $file)) {
110113
return true;
111114
}
112115

113116
//used to detect imagecreatefromstring
114-
if (preg_match('/will be returned on success\. &false; is returned if/m', $file)) {
117+
if (preg_match('/If the arguments are invalid, the function returns &false;/m', $file)) {
115118
return true;
116119
}
117120

generator/src/GenerateCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7474

7575
// Finally, let's edit the composer.json file
7676
$output->writeln('Editing composer.json');
77-
ComposerJsonEditor::editFiles(\array_values($modules));
77+
ComposerJsonEditor::editComposerFileForGeneration(\array_values($modules));
7878

7979
return 0;
8080
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
4+
namespace Safe;
5+
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
class ComposerJsonEditorTest extends TestCase
10+
{
11+
public function testFileListEditionForGeneration()
12+
{
13+
$oldList = [
14+
"deprecated/apc.php",
15+
"lib/special_cases.php",
16+
"generated/apache.php",
17+
];
18+
$modules = [
19+
'apache',
20+
'mysql'
21+
];
22+
23+
$newList = ComposerJsonEditor::editFilesListForGeneration($oldList, $modules);
24+
25+
$this->assertEquals([
26+
"deprecated/apc.php",
27+
"lib/special_cases.php",
28+
"generated/apache.php",
29+
"generated/mysql.php",
30+
], $newList);
31+
}
32+
33+
34+
public function testFileListEditionForDeprecation()
35+
{
36+
$oldList = [
37+
"generated/apache.php",
38+
"generated/apc.php",
39+
];
40+
41+
$newList = ComposerJsonEditor::editFileListForDeprecation($oldList, 'apc');
42+
43+
$this->assertEquals([
44+
"generated/apache.php",
45+
"deprecated/apc.php",
46+
], $newList);
47+
}
48+
}

generator/tests/DeprecateCommandTest.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,4 @@ public function testExceptionName()
1313
$this->assertEquals('Exceptions/ApcException.php', DeprecateCommand::getExceptionFilePath('apc'));
1414
}
1515

16-
public function testFileListEdition()
17-
{
18-
$oldList = [
19-
"generated/apache.php",
20-
"generated/apc.php",
21-
];
22-
23-
$newList = DeprecateCommand::editFileList($oldList, 'apc');
24-
25-
$this->assertEquals([
26-
"generated/apache.php",
27-
"deprecated/apc.php",
28-
], $newList);
29-
}
30-
3116
}

generator/tests/DocPageTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function testDetectFalsyFunction()
1717
$mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml');
1818
$fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml');
1919
$arrayReplace = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/array/functions/array-replace.xml');
20+
$mktime = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/mktime.xml');
2021

2122
$this->assertTrue($pregMatch->detectFalsyFunction());
2223
$this->assertFalse($implode->detectFalsyFunction());
@@ -27,6 +28,7 @@ public function testDetectFalsyFunction()
2728
$this->assertTrue($mcryptDecrypt->detectFalsyFunction());
2829
$this->assertTrue($fsockopen->detectFalsyFunction());
2930
$this->assertFalse($arrayReplace->detectFalsyFunction());
31+
$this->assertTrue($mktime->detectFalsyFunction());
3032
}
3133

3234
public function testDetectNullsyFunction()

0 commit comments

Comments
 (0)