From f066f49a2977aeca4b1a3219b07c0ccf71e04a63 Mon Sep 17 00:00:00 2001 From: Shish Date: Thu, 30 Jan 2025 20:03:33 +0000 Subject: [PATCH] Remove support for deprecated functions (which will be re-added later) Trying to make #503 easier to review - that PR removes manual deprecation and implements automatic deprecation; but removing manual deprecation _can_ be done by itself, and doing so means that the #503 diff can be a bit smaller. - --- composer.json | 12 +- deprecated/Exceptions/LibeventException.php | 11 - deprecated/Exceptions/MssqlException.php | 11 - deprecated/Exceptions/MysqliException.php | 11 - deprecated/Exceptions/PasswordException.php | 15 - deprecated/Exceptions/StatsException.php | 11 - deprecated/array.php | 301 --------- deprecated/datetime.php | 98 --- deprecated/functionsList.php | 63 -- deprecated/libevent.php | 496 -------------- deprecated/misc.php | 29 - deprecated/mssql.php | 426 ------------ deprecated/mysqli.php | 22 - deprecated/password.php | 127 ---- deprecated/stats.php | 108 ---- deprecated/strings.php | 677 -------------------- generator/safe.php | 2 - generator/src/ComposerJsonEditor.php | 43 +- generator/src/DeprecateCommand.php | 66 -- generator/tests/ComposerJsonEditorTest.php | 21 +- generator/tests/DeprecateCommandTest.php | 15 - 21 files changed, 7 insertions(+), 2558 deletions(-) delete mode 100644 deprecated/Exceptions/LibeventException.php delete mode 100644 deprecated/Exceptions/MssqlException.php delete mode 100644 deprecated/Exceptions/MysqliException.php delete mode 100644 deprecated/Exceptions/PasswordException.php delete mode 100644 deprecated/Exceptions/StatsException.php delete mode 100644 deprecated/array.php delete mode 100644 deprecated/datetime.php delete mode 100644 deprecated/functionsList.php delete mode 100644 deprecated/libevent.php delete mode 100644 deprecated/misc.php delete mode 100644 deprecated/mssql.php delete mode 100644 deprecated/mysqli.php delete mode 100644 deprecated/password.php delete mode 100644 deprecated/stats.php delete mode 100644 deprecated/strings.php delete mode 100644 generator/src/DeprecateCommand.php delete mode 100644 generator/tests/DeprecateCommandTest.php diff --git a/composer.json b/composer.json index 27ac5329..f905fcb6 100644 --- a/composer.json +++ b/composer.json @@ -7,20 +7,10 @@ "lib/DateTime.php", "lib/DateTimeImmutable.php", "lib/Exceptions/", - "deprecated/Exceptions/", "generated/Exceptions/" ], "files": [ - "deprecated/array.php", - "deprecated/datetime.php", - "deprecated/libevent.php", - "deprecated/misc.php", - "deprecated/password.php", - "deprecated/mssql.php", - "deprecated/stats.php", - "deprecated/strings.php", "lib/special_cases.php", - "deprecated/mysqli.php", "generated/apache.php", "generated/apcu.php", "generated/array.php", @@ -111,7 +101,7 @@ "php-parallel-lint/php-parallel-lint": "^1.4" }, "scripts": { - "lint": "parallel-lint deprecated/ lib/ tests/", + "lint": "parallel-lint lib/ tests/", "test": "phpunit", "phpstan": "phpstan analyse", "cs-fix": "phpcbf", diff --git a/deprecated/Exceptions/LibeventException.php b/deprecated/Exceptions/LibeventException.php deleted file mode 100644 index a6c541a5..00000000 --- a/deprecated/Exceptions/LibeventException.php +++ /dev/null @@ -1,11 +0,0 @@ - - * - * - * @param int $length If length is given and is positive, the string - * returned will contain at most length characters - * beginning from start (depending on the length of - * string). - * - * If length is given and is negative, then that many - * characters will be omitted from the end of string - * (after the start position has been calculated when a - * start is negative). If - * start denotes the position of this truncation or - * beyond, FALSE will be returned. - * - * If length is given and is 0, - * FALSE or NULL, an empty string will be returned. - * - * If length is omitted, the substring starting from - * start until the end of the string will be - * returned. - * @return string Returns the extracted part of string;, or - * an empty string. - * @throws StringsException - * @deprecated The Safe version of this function is no longer needed in PHP 8.0+ - * - */ -function substr(string $string, int $start, ?int $length = null): string -{ - error_clear_last(); - if ($length !== null) { - $result = \substr($string, $start, $length); - } else { - $result = \substr($string, $start); - } - if ($result === false) { - throw StringsException::createFromPhpError(); - } - return $result; -} - -/** - * Operates as sprintf but accepts an array of - * arguments, rather than a variable number of arguments. - * - * @param string $format The format string is composed of zero or more directives: - * ordinary characters (excluding %) that are - * copied directly to the result and conversion - * specifications, each of which results in fetching its - * own parameter. - * - * A conversion specification follows this prototype: - * %[argnum$][flags][width][.precision]specifier. - * - * An integer followed by a dollar sign $, - * to specify which number argument to treat in the conversion. - * - * - * Flags - * - * - * - * Flag - * Description - * - * - * - * - * - - * - * Left-justify within the given field width; - * Right justification is the default - * - * - * - * + - * - * Prefix positive numbers with a plus sign - * +; Default only negative - * are prefixed with a negative sign. - * - * - * - * (space) - * - * Pads the result with spaces. - * This is the default. - * - * - * - * 0 - * - * Only left-pads numbers with zeros. - * With s specifiers this can - * also right-pad with zeros. - * - * - * - * '(char) - * - * Pads the result with the character (char). - * - * - * - * - * - * - * An integer that says how many characters (minimum) - * this conversion should result in. - * - * A period . followed by an integer - * who's meaning depends on the specifier: - * - * - * - * For e, E, - * f and F - * specifiers: this is the number of digits to be printed - * after the decimal point (by default, this is 6). - * - * - * - * - * For g and G - * specifiers: this is the maximum number of significant - * digits to be printed. - * - * - * - * - * For s specifier: it acts as a cutoff point, - * setting a maximum character limit to the string. - * - * - * - * - * - * If the period is specified without an explicit value for precision, - * 0 is assumed. - * - * - * - * - * Specifiers - * - * - * - * Specifier - * Description - * - * - * - * - * % - * - * A literal percent character. No argument is required. - * - * - * - * b - * - * The argument is treated as an integer and presented - * as a binary number. - * - * - * - * c - * - * The argument is treated as an integer and presented - * as the character with that ASCII. - * - * - * - * d - * - * The argument is treated as an integer and presented - * as a (signed) decimal number. - * - * - * - * e - * - * The argument is treated as scientific notation (e.g. 1.2e+2). - * The precision specifier stands for the number of digits after the - * decimal point since PHP 5.2.1. In earlier versions, it was taken as - * number of significant digits (one less). - * - * - * - * E - * - * Like the e specifier but uses - * uppercase letter (e.g. 1.2E+2). - * - * - * - * f - * - * The argument is treated as a float and presented - * as a floating-point number (locale aware). - * - * - * - * F - * - * The argument is treated as a float and presented - * as a floating-point number (non-locale aware). - * Available as of PHP 5.0.3. - * - * - * - * g - * - * - * General format. - * - * - * Let P equal the precision if nonzero, 6 if the precision is omitted, - * or 1 if the precision is zero. - * Then, if a conversion with style E would have an exponent of X: - * - * - * If P > X ≥ −4, the conversion is with style f and precision P − (X + 1). - * Otherwise, the conversion is with style e and precision P − 1. - * - * - * - * - * G - * - * Like the g specifier but uses - * E and f. - * - * - * - * o - * - * The argument is treated as an integer and presented - * as an octal number. - * - * - * - * s - * - * The argument is treated and presented as a string. - * - * - * - * u - * - * The argument is treated as an integer and presented - * as an unsigned decimal number. - * - * - * - * x - * - * The argument is treated as an integer and presented - * as a hexadecimal number (with lowercase letters). - * - * - * - * X - * - * The argument is treated as an integer and presented - * as a hexadecimal number (with uppercase letters). - * - * - * - * - * - * - * General format. - * - * Let P equal the precision if nonzero, 6 if the precision is omitted, - * or 1 if the precision is zero. - * Then, if a conversion with style E would have an exponent of X: - * - * If P > X ≥ −4, the conversion is with style f and precision P − (X + 1). - * Otherwise, the conversion is with style e and precision P − 1. - * - * The c type specifier ignores padding and width - * - * Attempting to use a combination of the string and width specifiers with character sets that require more than one byte per character may result in unexpected results - * - * Variables will be co-erced to a suitable type for the specifier: - * - * Type Handling - * - * - * - * Type - * Specifiers - * - * - * - * - * string - * s - * - * - * integer - * - * d, - * u, - * c, - * o, - * x, - * X, - * b - * - * - * - * double - * - * g, - * G, - * e, - * E, - * f, - * F - * - * - * - * - * - * @param array $args - * @return string Return array values as a formatted string according to - * format. - * @throws StringsException - * @deprecated The Safe version of this function is no longer needed in PHP 8.0+ - */ -function vsprintf(string $format, array $args): string -{ - error_clear_last(); - $result = \vsprintf($format, $args); - if ($result === false) { - throw StringsException::createFromPhpError(); - } - return $result; -} diff --git a/generator/safe.php b/generator/safe.php index cec964a5..5477a1f2 100755 --- a/generator/safe.php +++ b/generator/safe.php @@ -6,12 +6,10 @@ use Safe\GenerateCommand; use Safe\ScanObjectsCommand; -use Safe\DeprecateCommand; use Symfony\Component\Console\Application; $application = new Application(); $application->addCommands([new GenerateCommand()]); $application->addCommands([new ScanObjectsCommand()]); -$application->addCommands([new DeprecateCommand()]); $application->run(); diff --git a/generator/src/ComposerJsonEditor.php b/generator/src/ComposerJsonEditor.php index 7ff7a55c..a4ad086f 100644 --- a/generator/src/ComposerJsonEditor.php +++ b/generator/src/ComposerJsonEditor.php @@ -10,28 +10,13 @@ class ComposerJsonEditor { private const COMPOSER_FILEPATH = __DIR__.'/../../composer.json'; - - public static function editComposerFileForDeprecation(string $moduleName): void - { - - $composerContent = file_get_contents(self::COMPOSER_FILEPATH); - if ($composerContent === false) { - throw new \RuntimeException('Error while loading composer.json file for edition.'); - } - /** @var array> $composerJson */ - $composerJson = \json_decode($composerContent, true); - $composerJson['autoload']['files'] = self::editFileListForDeprecation($composerJson['autoload']['files'], $moduleName); - - $newContent = \json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); - \file_put_contents(self::COMPOSER_FILEPATH, $newContent); - } /** * @param string[] $modules A list of modules */ public static function editComposerFileForGeneration(array $modules): void { - + $composerContent = file_get_contents(self::COMPOSER_FILEPATH); if ($composerContent === false) { throw new \RuntimeException('Error while loading composer.json file for edition.'); @@ -43,10 +28,10 @@ public static function editComposerFileForGeneration(array $modules): void $newContent = \json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); \file_put_contents(self::COMPOSER_FILEPATH, $newContent); } - - - - + + + + /** * @param string[] $oldFiles * @param string[] $modules A list of modules @@ -62,22 +47,4 @@ public static function editFilesListForGeneration(array $oldFiles, array $module } return $files; } - - /** - * @param string[] $fileList - * @return string[] - */ - public static function editFileListForDeprecation(array $fileList, string $moduleName): array - { - $newList = []; - foreach ($fileList as $fileName) { - if ($fileName === "generated/$moduleName.php") { - $newList[] = "deprecated/$moduleName.php"; - } else { - $newList[] = $fileName; - } - } - - return $newList; - } } diff --git a/generator/src/DeprecateCommand.php b/generator/src/DeprecateCommand.php deleted file mode 100644 index 136f50be..00000000 --- a/generator/src/DeprecateCommand.php +++ /dev/null @@ -1,66 +0,0 @@ -setName('deprecate') - ->setDescription('Flag a module as deprecated and save it into the deprecated directory') - ->addArgument('module', InputArgument::REQUIRED, 'the module to deprecate') - ; - } - - protected function execute(InputInterface $input, OutputInterface $output): int - { - /** @var string $moduleName */ - $moduleName = $input->getArgument('module'); - - $moduleFilePath = self::GENERATE_DIRECTORY."$moduleName.php"; - if (!\file_exists($moduleFilePath)) { - throw new \RuntimeException("Module $moduleName is not maintained!"); - } - - $output->writeln("Move $moduleName.php to deprecated"); - $success = \rename($moduleFilePath, self::DEPRECATE_DIRECTORY."$moduleName.php"); - if (!$success) { - throw new \RuntimeException("Could not move the file."); - } - - $exceptionFilePath = self::GENERATE_DIRECTORY.self::getExceptionFilePath($moduleName); - if (\file_exists($exceptionFilePath)) { - $output->writeln("Move exception file to deprecated"); - $success = \rename($exceptionFilePath, self::DEPRECATE_DIRECTORY.self::getExceptionFilePath($moduleName)); - if (!$success) { - throw new \RuntimeException("Could not move the file."); - } - } - - $output->writeln('Editing composer.json'); - ComposerJsonEditor::editComposerFileForDeprecation($moduleName); - - $generatedListFile = self::GENERATE_DIRECTORY.'functionsList.php'; - $deprecatedListFile = self::DEPRECATE_DIRECTORY.'functionsList.php'; - $output->writeln("Don't forget to edit $generatedListFile and $deprecatedListFile !"); - - return 0; - } - - public static function getExceptionFilePath(string $moduleName): string - { - return "Exceptions/".ucfirst($moduleName)."Exception.php"; - } -} diff --git a/generator/tests/ComposerJsonEditorTest.php b/generator/tests/ComposerJsonEditorTest.php index a9d181b4..15cdd33d 100644 --- a/generator/tests/ComposerJsonEditorTest.php +++ b/generator/tests/ComposerJsonEditorTest.php @@ -4,7 +4,6 @@ namespace Safe; - use PHPUnit\Framework\TestCase; class ComposerJsonEditorTest extends TestCase @@ -12,7 +11,6 @@ class ComposerJsonEditorTest extends TestCase public function testFileListEditionForGeneration(): void { $oldList = [ - "deprecated/apc.php", "lib/special_cases.php", "generated/apache.php", ]; @@ -24,26 +22,9 @@ public function testFileListEditionForGeneration(): void $newList = ComposerJsonEditor::editFilesListForGeneration($oldList, $modules); $this->assertEquals([ - "deprecated/apc.php", "lib/special_cases.php", "generated/apache.php", "generated/mysql.php", ], $newList); } - - - public function testFileListEditionForDeprecation(): void - { - $oldList = [ - "generated/apache.php", - "generated/apc.php", - ]; - - $newList = ComposerJsonEditor::editFileListForDeprecation($oldList, 'apc'); - - $this->assertEquals([ - "generated/apache.php", - "deprecated/apc.php", - ], $newList); - } -} \ No newline at end of file +} diff --git a/generator/tests/DeprecateCommandTest.php b/generator/tests/DeprecateCommandTest.php deleted file mode 100644 index 84832ce9..00000000 --- a/generator/tests/DeprecateCommandTest.php +++ /dev/null @@ -1,15 +0,0 @@ -assertEquals('Exceptions/PasswordException.php', DeprecateCommand::getExceptionFilePath('password')); - } -}