diff --git a/app/V1Module/presenters/UploadedFilesPresenter.php b/app/V1Module/presenters/UploadedFilesPresenter.php index 09d7a86ee..65a99dbda 100644 --- a/app/V1Module/presenters/UploadedFilesPresenter.php +++ b/app/V1Module/presenters/UploadedFilesPresenter.php @@ -25,7 +25,6 @@ use App\Security\ACL\IUploadedFilePermissions; use App\Security\ACL\IUploadedPartialFilePermissions; use App\Security\ACL\IAssignmentSolutionPermissions; -use ForceUTF8\Encoding; use Nette\Utils\Strings; use Nette\Http\IResponse; use Tracy\ILogger; diff --git a/app/V1Module/presenters/base/BasePresenter.php b/app/V1Module/presenters/base/BasePresenter.php index 383a64044..57f6fe0cc 100644 --- a/app/V1Module/presenters/base/BasePresenter.php +++ b/app/V1Module/presenters/base/BasePresenter.php @@ -6,7 +6,6 @@ use App\Model\Entity\User; use App\Security\AccessToken; use App\Security\Identity; -use Nette\Utils\Strings; use App\Exceptions\BadRequestException; use App\Exceptions\ForbiddenRequestException; use App\Exceptions\WrongHttpMethodException; @@ -265,7 +264,7 @@ private function getQueryField($param, $required = true) private function validateValue($param, $value, $validationRule, $msg = null) { foreach (["int", "integer"] as $rule) { - if ($validationRule === $rule || Strings::startsWith($validationRule, $rule . ":")) { + if ($validationRule === $rule || str_starts_with($validationRule, $rule . ":")) { throw new LogicException("Validation rule '$validationRule' will not work for request parameters"); } } diff --git a/app/V1Module/security/ACLModuleBuilder.php b/app/V1Module/security/ACLModuleBuilder.php index f1d78d6c2..2a5b4d42e 100644 --- a/app/V1Module/security/ACLModuleBuilder.php +++ b/app/V1Module/security/ACLModuleBuilder.php @@ -14,7 +14,7 @@ class ACLModuleBuilder public function getClassName($interfaceName, $uniqueId) { $interfaceName = Strings::after($interfaceName, '\\', -1) ?: $interfaceName; - if (Strings::startsWith($interfaceName, "I")) { + if (str_starts_with($interfaceName, "I")) { $rest = Strings::after($interfaceName, "I"); if (Strings::firstUpper($rest) === $rest) { @@ -42,7 +42,7 @@ public function build($interfaceName, $name, $uniqueId): ClassType $class->addMethod("getResourceName")->addBody('return ?;', [$name]); foreach ($interface->getMethods(ReflectionMethod::IS_ABSTRACT) as $method) { - $isNameCorrect = Strings::startsWith($method->getName(), "can"); + $isNameCorrect = str_starts_with($method->getName(), "can"); /** @var ?ReflectionNamedType $methodReturnType */ $methodReturnType = $method->getReturnType(); $isBoolean = $methodReturnType !== null ? $methodReturnType->getName() === "bool" : false; diff --git a/app/V1Module/security/AccessManager.php b/app/V1Module/security/AccessManager.php index 1d10b0f40..0ac504d53 100644 --- a/app/V1Module/security/AccessManager.php +++ b/app/V1Module/security/AccessManager.php @@ -15,9 +15,6 @@ use Firebase\JWT\Key; use DomainException; use UnexpectedValueException; -use Firebase\JWT\ExpiredException; -use Firebase\JWT\SignatureInvalidException; -use Firebase\JWT\BeforeValidException; class AccessManager { @@ -247,7 +244,7 @@ public static function getGivenAccessToken(IRequest $request) $parts = Strings::split($authorizationHeader, "/ /"); if (count($parts) === 2) { list($bearer, $accessToken) = $parts; - if ($bearer === "Bearer" && !Strings::contains($accessToken, " ") && Strings::length($accessToken) > 0) { + if ($bearer === "Bearer" && !str_contains($accessToken, " ") && Strings::length($accessToken) > 0) { return $accessToken; } } diff --git a/app/V1Module/security/Roles.php b/app/V1Module/security/Roles.php index 2912a6196..c6dc374bc 100644 --- a/app/V1Module/security/Roles.php +++ b/app/V1Module/security/Roles.php @@ -2,8 +2,6 @@ namespace App\Security; -use Nette\Utils\Strings; - /** * Class used for management of user roles, which are dynamically loaded from * permission configuration file. @@ -43,7 +41,7 @@ public function isInRole(string $actualTestedRole, string $minimalRequestedRole) return true; } - if ($actualTestedRole === self::SUPERADMIN_ROLE && !Strings::startsWith($minimalRequestedRole, 'scope-')) { + if ($actualTestedRole === self::SUPERADMIN_ROLE && !str_starts_with($minimalRequestedRole, 'scope-')) { return true; // special case -- superadmin takes it all, except for the scopes } diff --git a/app/commands/DoctrineFixtures.php b/app/commands/DoctrineFixtures.php index dd8a05713..2166273cb 100644 --- a/app/commands/DoctrineFixtures.php +++ b/app/commands/DoctrineFixtures.php @@ -7,7 +7,6 @@ use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Id\AssignedGenerator; use Nette\Utils\Finder; -use Nette\Utils\Strings; use SplFileInfo; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -136,12 +135,12 @@ protected function clearDatabase() } if ($platform === 'mysql') { - if (!Strings::startsWith($tableName, '``')) { + if (!str_starts_with($tableName, '``')) { $tableName = '`' . $tableName . '`'; } } else { if ($platform === 'sqlite') { - if (!Strings::startsWith($tableName, '``')) { + if (!str_starts_with($tableName, '``')) { $tableName = '"' . $tableName . '"'; } } diff --git a/app/commands/runtimes/RuntimeImport.php b/app/commands/runtimes/RuntimeImport.php index bd60ecbdb..4fe629767 100644 --- a/app/commands/runtimes/RuntimeImport.php +++ b/app/commands/runtimes/RuntimeImport.php @@ -492,8 +492,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // open the ZIP archive for reading $zip = new ZipArchive(); - // TODO: ZipArchive::RDONLY flag would be nice here, but it requires PHP 7.4.3+ - $opened = $zip->open($fileName); + $opened = $zip->open($fileName, ZipArchive::RDONLY); if ($opened !== true) { throw new RuntimeException("Unable to open file '$fileName' for reading (code $opened)."); } diff --git a/app/helpers/BasicAuthHelper.php b/app/helpers/BasicAuthHelper.php index 1acbc83ca..9c6e7f396 100644 --- a/app/helpers/BasicAuthHelper.php +++ b/app/helpers/BasicAuthHelper.php @@ -11,7 +11,6 @@ */ class BasicAuthHelper { - /** * Extracts the username and password from the Authorization header of the HTTP request. * @param IRequest $req HTTP request @@ -21,13 +20,13 @@ class BasicAuthHelper public static function getCredentials(IRequest $req) { $auth = $req->getHeader("Authorization"); - if ($auth === null || Strings::startsWith($auth, "Basic ") === false) { + if ($auth === null || str_starts_with($auth, "Basic ") === false) { throw new HttpBasicAuthException("The request from backend-service must contain HTTP Basic authentication."); } $encodedCredentials = Strings::substring($auth, strlen("Basic ")); $decodedCredentials = base64_decode($encodedCredentials); - if (!Strings::contains($decodedCredentials, ":")) { + if (!str_contains($decodedCredentials, ":")) { throw new HttpBasicAuthException( "HTTP 'Authorization' header must be in the format of 'Basic ' + base64(username:password)" ); diff --git a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/ExtractBox.php b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/ExtractBox.php index 148362498..61c5bf7e4 100644 --- a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/ExtractBox.php +++ b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/ExtractBox.php @@ -8,11 +8,8 @@ use App\Helpers\ExerciseConfig\Pipeline\Box\Params\Priorities; use App\Helpers\ExerciseConfig\Pipeline\Box\Params\TaskCommands; use App\Helpers\ExerciseConfig\Pipeline\Box\Params\TaskType; -use App\Helpers\ExerciseConfig\Pipeline\Ports\Port; -use App\Helpers\ExerciseConfig\Pipeline\Ports\PortMeta; use App\Helpers\ExerciseConfig\VariableTypes; use App\Helpers\JobConfig\Tasks\Task; -use Nette\Utils\Strings; use Nette\Utils\Random; /** diff --git a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmCompilationBox.php b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmCompilationBox.php index 8cc3a8e70..671673610 100644 --- a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmCompilationBox.php +++ b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmCompilationBox.php @@ -8,11 +8,8 @@ use App\Helpers\ExerciseConfig\Pipeline\Box\Params\Priorities; use App\Helpers\ExerciseConfig\Pipeline\Box\Params\TaskCommands; use App\Helpers\ExerciseConfig\Pipeline\Box\Params\TaskType; -use App\Helpers\ExerciseConfig\Pipeline\Ports\Port; -use App\Helpers\ExerciseConfig\Pipeline\Ports\PortMeta; use App\Helpers\ExerciseConfig\VariableTypes; use App\Helpers\JobConfig\Tasks\Task; -use Nette\Utils\Strings; /** * Box which represents custom compilation to JVM bytecode. diff --git a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmRunBox.php b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmRunBox.php index 78e1f2cf5..c2d938960 100644 --- a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmRunBox.php +++ b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmRunBox.php @@ -4,8 +4,6 @@ use App\Exceptions\ExerciseConfigException; use App\Helpers\ExerciseConfig\Compilation\CompilationParams; -use App\Helpers\ExerciseConfig\Pipeline\Ports\Port; -use App\Helpers\ExerciseConfig\Pipeline\Ports\PortMeta; use App\Helpers\ExerciseConfig\VariableTypes; use Nette\Utils\Strings; @@ -117,7 +115,7 @@ public function compile(CompilationParams $params): array // name from class filename, so we are gonna be nice and do this tedious job // instead of java runtime, you are welcome $runnerClass = $this->getInputPortValue(self::$RUNNER_FILE_PORT_KEY)->getValue(); - if (Strings::endsWith($runnerClass, ".class")) { + if (str_ends_with($runnerClass, ".class")) { $runnerLength = Strings::length($runnerClass); // as we can see above, we have runner class with '.class' extension // to be able to run this class we have to get its name without diff --git a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/Python3RunBox.php b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/Python3RunBox.php index d9ba18051..44dab3a06 100644 --- a/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/Python3RunBox.php +++ b/app/helpers/ExerciseConfig/Pipeline/Box/Boxes/Python3RunBox.php @@ -4,11 +4,9 @@ use App\Exceptions\ExerciseConfigException; use App\Helpers\ExerciseConfig\Compilation\CompilationParams; -use App\Helpers\ExerciseConfig\Pipeline\Box\Params\ConfigParams; use App\Helpers\ExerciseConfig\Pipeline\Ports\Port; use App\Helpers\ExerciseConfig\Pipeline\Ports\PortMeta; use App\Helpers\ExerciseConfig\VariableTypes; -use Nette\Utils\Strings; /** * Box which represents execution python script. diff --git a/app/helpers/ExerciseConfig/Variables/Variable.php b/app/helpers/ExerciseConfig/Variables/Variable.php index c025068de..9257b4f79 100644 --- a/app/helpers/ExerciseConfig/Variables/Variable.php +++ b/app/helpers/ExerciseConfig/Variables/Variable.php @@ -268,7 +268,7 @@ public function getDirPrefixedValueAsArray(string $prefix = ""): array public function getValue(string $prefix = "") { $value = $this->value; - if (is_scalar($value) && Strings::startsWith($value, self::$ESCAPE_CHAR . self::$REFERENCE_KEY)) { + if (is_scalar($value) && str_starts_with($value, self::$ESCAPE_CHAR . self::$REFERENCE_KEY)) { return Strings::substring($value, 1); } @@ -343,7 +343,7 @@ public function getDirectory(): ?string public function getReference(): ?string { $val = $this->value; - if (is_scalar($val) && Strings::startsWith($val, self::$REFERENCE_KEY)) { + if (is_scalar($val) && str_starts_with($val, self::$REFERENCE_KEY)) { return Strings::substring($val, 1); } @@ -357,7 +357,7 @@ public function getReference(): ?string public function isReference(): bool { $val = $this->value; - return is_scalar($val) && Strings::startsWith($val, self::$REFERENCE_KEY); + return is_scalar($val) && str_starts_with($val, self::$REFERENCE_KEY); } diff --git a/app/helpers/FileStorage/File/ArchivedImmutableFile.php b/app/helpers/FileStorage/File/ArchivedImmutableFile.php index 906176b9a..08b2a7f7d 100644 --- a/app/helpers/FileStorage/File/ArchivedImmutableFile.php +++ b/app/helpers/FileStorage/File/ArchivedImmutableFile.php @@ -75,8 +75,7 @@ public function __construct( private function openZip() { $zip = new ZipArchive(); - // TODO: ZipArchive::RDONLY flag would be nice here, but it requires PHP 7.4.3+ - $res = $zip->open($this->archivePath); + $res = $zip->open($this->archivePath, ZipArchive::RDONLY); if ($res !== true) { throw new FileStorageException("Unable to open ZIP archive (code $res).", $this->archivePath); } @@ -160,8 +159,7 @@ public function isZipArchive(): bool ZipFileStorage::extractZipEntryToFile($sourceZip, $this->archivePath, $this->entry, $path); $zip = new ZipArchive(); - // TODO: ZipArchive::RDONLY flag would be nice here, but it requires PHP 7.4.3+ - $res = $zip->open($path); + $res = $zip->open($path, ZipArchive::RDONLY); if ($res === true) { $zip->close(); } diff --git a/app/helpers/FileStorage/File/LocalImmutableFile.php b/app/helpers/FileStorage/File/LocalImmutableFile.php index 910caf201..9ef3fb389 100644 --- a/app/helpers/FileStorage/File/LocalImmutableFile.php +++ b/app/helpers/FileStorage/File/LocalImmutableFile.php @@ -116,8 +116,7 @@ public function getDigest(string $algorithm = IImmutableFile::DIGEST_ALGORITHM_S public function isZipArchive(): bool { $zip = new ZipArchive(); - // TODO: ZipArchive::RDONLY flag would be nice here, but it requires PHP 7.4.3+ - $res = $zip->open($this->realPath); + $res = $zip->open($this->realPath, ZipArchive::RDONLY); if ($res === true) { $zip->close(); } @@ -127,8 +126,7 @@ public function isZipArchive(): bool public function getZipEntries(): array { $zip = new ZipArchive(); - // TODO: ZipArchive::RDONLY flag would be nice here, but it requires PHP 7.4.3+ - $res = $zip->open($this->realPath); + $res = $zip->open($this->realPath, ZipArchive::RDONLY); if ($res !== true) { throw new FileStorageException( "Cannot list entries from a file which is not a ZIP archive.", diff --git a/app/helpers/FileStorage/LocalStorage/LocalFileStorage.php b/app/helpers/FileStorage/LocalStorage/LocalFileStorage.php index 6b37f845c..b2c6e29e2 100644 --- a/app/helpers/FileStorage/LocalStorage/LocalFileStorage.php +++ b/app/helpers/FileStorage/LocalStorage/LocalFileStorage.php @@ -4,7 +4,6 @@ use App\Helpers\TmpFilesHelper; use Nette\Utils\Arrays; -use Nette\Utils\Strings; use Nette\SmartObject; use ZipArchive; use FilesystemIterator; @@ -33,7 +32,7 @@ class LocalFileStorage implements IFileStorage protected $rootDirectory; - public function getRootDirectory(): string + public function getRootDirectory(): ?string { return $this->rootDirectory; } @@ -65,7 +64,7 @@ private static function normalizePath(string $path): string $path = preg_replace('@/[.]/@', '/', $path); $path = preg_replace('@[/\\\\]+@', '/', $path); $path = preg_replace('@(^[.]/)|(/[.]?$)@', '', $path); - if (Strings::startsWith($path, '../') || Strings::contains($path, '/../') || Strings::endsWith($path, '/..')) { + if (str_starts_with($path, '../') || str_contains($path, '/../') || str_ends_with($path, '/..')) { throw new FileStorageException("Substring '..' must not be present in any path.", $path); } return $path; @@ -81,13 +80,11 @@ private static function normalizePath(string $path): string */ private function decodePath(string &$path, bool $exists = null, $mkdir = false): array { - $path = self::normalizePath($path); - $tokens = explode('#', $path, 2); array_push($tokens, null); // make sure second item always exists [$realPath, $zipEntry] = $tokens; - $realPath = $this->rootDirectory . '/' . $realPath; + $realPath = $this->rootDirectory . '/' . self::normalizePath($realPath); if (is_dir($realPath)) { throw new FileStorageException("Given path refers to a directory.", $path); } @@ -145,7 +142,7 @@ private function removeEmptyDirectory(string $path): void closedir($dh); // It is empty, let's proceed! - if (@rmdir($realPath) && Strings::contains($path, '/')) { + if (@rmdir($realPath) && str_contains($path, '/')) { $this->removeEmptyDirectory(dirname($path)); } } @@ -398,7 +395,7 @@ public function extract(string $storagePath, string $localPath, bool $overwrite if (file_exists($srcReal) && !@unlink($srcReal)) { throw new FileStorageException("Unable to delete file in the storage.", $storagePath); } - if (Strings::contains($storagePath, '/')) { + if (str_contains($storagePath, '/')) { // removing unnecessary empty directories $this->removeEmptyDirectory(dirname($storagePath)); } @@ -417,7 +414,7 @@ public function delete(string $path): bool if (!@unlink($realPath)) { throw new FileStorageException("Unable to delete file in the storage.", $path); } - if (Strings::contains($path, '/')) { + if (str_contains($path, '/')) { // removing unnecessary empty directories $this->removeEmptyDirectory(dirname($path)); } @@ -434,7 +431,7 @@ public function delete(string $path): bool public function deleteOldFiles(string $glob, int $threshold): int { $glob = $this->rootDirectory . '/' . $glob; - $rootDirLen = strlen($this->rootDirectory); + $rootDirLen = strlen($this->rootDirectory ?? ''); $deleted = 0; $affectedDirectories = []; @@ -481,7 +478,7 @@ public function deleteByFilter(string $prefix, callable $filter): int return 0; // nothinth to do } - $rootDirLen = strlen($this->rootDirectory) + 1; // plus 1 for '/'; + $rootDirLen = strlen($this->rootDirectory ?? '') + 1; // plus 1 for '/'; $dirIterator = new RecursiveDirectoryIterator( $root, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS @@ -491,11 +488,11 @@ public function deleteByFilter(string $prefix, callable $filter): int // iterate over files and filter them $toDelete = []; // we store the paths as a list first to avoid any iterator confusions foreach ($recursiveIterator as $realPath) { - if (!Strings::startsWith($realPath, $root)) { + if (!str_starts_with($realPath, $root)) { throw new FileStorageException("Iterator returned a file outside the root directory.", $realPath); } $path = substr($realPath, $rootDirLen); // get the suffix without the root directory - if (!$prefix || Strings::startsWith($path, $prefix)) { + if (!$prefix || str_starts_with($path, $prefix)) { $file = new LocalImmutableFile($realPath, $path); if (!$filter($file)) { $toDelete[] = $path; diff --git a/app/helpers/FileStorage/LocalStorage/ZipFileStorage.php b/app/helpers/FileStorage/LocalStorage/ZipFileStorage.php index 8cbb007dc..57affbc9c 100644 --- a/app/helpers/FileStorage/LocalStorage/ZipFileStorage.php +++ b/app/helpers/FileStorage/LocalStorage/ZipFileStorage.php @@ -3,11 +3,9 @@ namespace App\Helpers\FileStorage; use App\Helpers\TmpFilesHelper; -use Nette\Utils\Arrays; use Nette\Utils\Strings; use Nette\SmartObject; use ZipArchive; -use Exception; /** * Simplified implementation of file storage over single ZIP file. @@ -81,7 +79,7 @@ private function closeZipArchive(): void private function setCompressionLevel(string $storagePath, ?int $level = null): void { if ($level === null) { - $level = Strings::endsWith(Strings::lower($storagePath), '.zip') + $level = str_ends_with(Strings::lower($storagePath), '.zip') ? ZipArchive::CM_STORE : ZipArchive::CM_DEFAULT; } $this->zip->setCompressionName($storagePath, $level); @@ -271,14 +269,11 @@ public function storeFile(string $localPath, string $storagePath, bool $move = t throw new FileStorageException("Given file is not accessible for reading.", $localPath); } - // TODO: PHP 8.0 introduced addFile() flags (especially ZipArchive::FL_OVERWRITE), which may replace this. - if ($overwrite) { - $this->zip->deleteName($storagePath); - } elseif ($this->zip->statName($storagePath)) { + if (!$overwrite && $this->zip->statName($storagePath)) { throw new FileStorageException("Target entry already exists.", $storagePath); } - if (!$this->zip->addFile($localPath, $storagePath)) { + if (!$this->zip->addFile($localPath, $storagePath, 0, 0, ZipArchive::FL_OVERWRITE)) { throw new FileStorageException("Unable to add file into ZIP archive.", $localPath); } $this->setCompressionLevel($storagePath); // make sure proper compression level is selected @@ -295,14 +290,11 @@ public function storeContents($contents, string $storagePath, bool $overwrite = throw new FileStorageException("The ZIP archive has already been closed.", $this->archivePath); } - // TODO: PHP 8.0 introduced addFile() flags (especially ZipArchive::FL_OVERWRITE), which may replace this. - if ($overwrite) { - $this->zip->deleteName($storagePath); - } elseif ($this->zip->statName($storagePath)) { + if (!$overwrite && $this->zip->statName($storagePath)) { throw new FileStorageException("Target entry already exists.", $storagePath); } - if (!$this->zip->addFromString($storagePath, $contents)) { + if (!$this->zip->addFromString($storagePath, $contents, ZipArchive::FL_OVERWRITE)) { throw new FileStorageException("Unable to add contents into ZIP archive.", $this->archivePath); } @@ -428,10 +420,10 @@ public function deleteByFilter(string $prefix, callable $filter): int $toDelete = []; // we store the paths as a list first to avoid any iterator confusions for ($i = 0; $i < $this->zip->numFiles; ++$i) { $path = $this->zip->getNameIndex($i); - if (Strings::endsWith($path, '/')) { + if (str_ends_with($path, '/')) { continue; // skipping directories } - if ($prefix && !Strings::startsWith($path, $prefix)) { + if ($prefix && !str_starts_with($path, $prefix)) { continue; // skipping entries that do not match the prefix } diff --git a/app/helpers/FileStorageManager.php b/app/helpers/FileStorageManager.php index 1e658351e..697badd3e 100644 --- a/app/helpers/FileStorageManager.php +++ b/app/helpers/FileStorageManager.php @@ -236,7 +236,7 @@ private function appendFileToStream(string $path, $targetStream) /** * Concatenate all partial file chunks into a final result -- the uploaded file. - * @param UploadedPartialFile $file entity that keeps track about partial uploads of one file + * @param UploadedPartialFile $partFile entity that keeps track about partial uploads of one file * @param UploadedFile $file final uploaded file database entity * @throws FileStorageException */ diff --git a/app/helpers/Pagination.php b/app/helpers/Pagination.php index 0cbb29165..4d6005127 100644 --- a/app/helpers/Pagination.php +++ b/app/helpers/Pagination.php @@ -71,7 +71,7 @@ public function __construct( $this->limit = $limit < 0 ? null : $limit; $this->originalOrderBy = $orderBy; $this->locale = $locale; - $this->order = $orderBy !== null ? !Strings::startsWith($orderBy, "!") : true; + $this->order = $orderBy !== null ? !str_starts_with($orderBy, "!") : true; $this->orderBy = $this->order ? $orderBy : Strings::substring($orderBy, 1); if ($knownFilters !== null) { diff --git a/app/helpers/PermissionHints.php b/app/helpers/PermissionHints.php index 232bbf7ee..79137d22a 100644 --- a/app/helpers/PermissionHints.php +++ b/app/helpers/PermissionHints.php @@ -3,7 +3,6 @@ namespace App\Helpers; use Nette\StaticClass; -use Nette\Utils\Strings; use ReflectionNamedType; use ReflectionClass; use ReflectionMethod; @@ -55,7 +54,7 @@ protected static function generateAclMethods($aclModule) { $reflectionClass = new ReflectionClass($aclModule); foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) { - if (!Strings::startsWith($method->getName(), "can")) { + if (!str_starts_with($method->getName(), "can")) { continue; } diff --git a/app/helpers/SisHelper/SisHelper.php b/app/helpers/SisHelper/SisHelper.php index cc5b34ece..7648029da 100644 --- a/app/helpers/SisHelper/SisHelper.php +++ b/app/helpers/SisHelper/SisHelper.php @@ -7,7 +7,6 @@ use Nette; use GuzzleHttp; use Nette\Utils\Json; -use Nette\Utils\Strings; class SisHelper { @@ -33,7 +32,7 @@ public function __construct($apiBase, $faculty, $secret, GuzzleHttp\HandlerStack $this->faculty = $faculty; $this->secret = $secret; - if (!Strings::endsWith($this->apiBase, '/')) { + if (!str_ends_with($this->apiBase, '/')) { $this->apiBase .= '/'; } diff --git a/app/helpers/SubmissionHelper/SubmissionHelper.php b/app/helpers/SubmissionHelper/SubmissionHelper.php index 382bf3d4f..ea32f66bc 100644 --- a/app/helpers/SubmissionHelper/SubmissionHelper.php +++ b/app/helpers/SubmissionHelper/SubmissionHelper.php @@ -15,7 +15,6 @@ use App\Helpers\JobConfig\JobConfig; use App\Helpers\JobConfig\Generator as JobConfigGenerator; use App\Helpers\ExerciseConfig\Compilation\CompilationParams; -use App\Model\Entity\Assignment; use App\Model\Entity\AssignmentSolution; use App\Model\Entity\AssignmentSolutionSubmission; use App\Model\Entity\HardwareGroup; @@ -27,18 +26,14 @@ use App\Model\Entity\SubmissionFailure; use App\Model\Entity\UploadedFile; use App\Model\Entity\User; -use App\Model\Repository\Assignments; use App\Model\Repository\AssignmentSolutions; use App\Model\Repository\AssignmentSolutionSubmissions; use App\Model\Repository\ReferenceExerciseSolutions; use App\Model\Repository\ReferenceSolutionSubmissions; use App\Model\Repository\SubmissionFailures; -use App\Model\Repository\Solutions; use App\Model\Repository\UploadedFiles; -use App\Model\Repository\RuntimeEnvironments; use Nette\Http\IResponse; use Nette\Utils\Strings; -use Nette\Utils\Arrays; use ZMQSocketException; use Exception; @@ -258,7 +253,7 @@ private function isSingleZipFile(array $files): bool } $file = reset($files); - if (!Strings::endsWith(Strings::lower($file->getName()), '.zip')) { + if (!str_ends_with(Strings::lower($file->getName()), '.zip')) { return false; // not zip extension } diff --git a/tests/ExerciseConfig/Compilation/BaseCompiler.phpt b/tests/ExerciseConfig/Compilation/BaseCompiler.phpt index 48ba8e8fa..bb65d09f2 100644 --- a/tests/ExerciseConfig/Compilation/BaseCompiler.phpt +++ b/tests/ExerciseConfig/Compilation/BaseCompiler.phpt @@ -333,14 +333,14 @@ class TestBaseCompiler extends Tester\TestCase $it = 0; $initiationMkdir = $jobConfig->getTasks()[0]; - Assert::true(Strings::startsWith($initiationMkdir->getId(), "initiation_")); - Assert::true(Strings::endsWith($initiationMkdir->getId(), "..mkdir." . $it++)); + Assert::true(str_starts_with($initiationMkdir->getId(), "initiation_")); + Assert::true(str_ends_with($initiationMkdir->getId(), "..mkdir." . $it++)); Assert::equal(Priorities::$DEFAULT, $initiationMkdir->getPriority()); Assert::count(0, $initiationMkdir->getDependencies()); Assert::equal("mkdir", $initiationMkdir->getCommandBinary()); Assert::count(1, $initiationMkdir->getCommandArguments()); Assert::true( - Strings::startsWith($initiationMkdir->getCommandArguments()[0], ConfigParams::$SOURCE_DIR . "initiation_") + str_starts_with($initiationMkdir->getCommandArguments()[0], ConfigParams::$SOURCE_DIR . "initiation_") ); Assert::null($initiationMkdir->getType()); Assert::equal(null, $initiationMkdir->getTestId()); diff --git a/tests/ExerciseConfig/Compilation/DirectoriesResolver.phpt b/tests/ExerciseConfig/Compilation/DirectoriesResolver.phpt index f587e4737..c4999c8be 100644 --- a/tests/ExerciseConfig/Compilation/DirectoriesResolver.phpt +++ b/tests/ExerciseConfig/Compilation/DirectoriesResolver.phpt @@ -14,7 +14,6 @@ use App\Helpers\ExerciseConfig\Pipeline\Ports\PortMeta; use App\Helpers\ExerciseConfig\Variable; use App\Helpers\ExerciseConfig\VariablesTable; use App\Helpers\ExerciseConfig\VariableTypes; -use Nette\Utils\Strings; use Tester\Assert; @@ -121,12 +120,12 @@ class TestDirectoriesResolver extends Tester\TestCase Assert::count(1, $mkdirCustomA->getChildren()); Assert::count(0, $mkdirCustomA->getDependencies()); Assert::equal(null, $mkdirCustomA->getTestId()); - Assert::true(Strings::startsWith($mkdirCustomA->getBox()->getDirectory(), "custom_")); + Assert::true(str_starts_with($mkdirCustomA->getBox()->getDirectory(), "custom_")); Assert::equal(17, strlen($mkdirCustomA->getBox()->getDirectory())); Assert::equal("mkdir", $mkdirCustomA->getBox()->getType()); Assert::count(1, $mkdirCustomA->getBox()->getInputPorts()); Assert::true( - Strings::startsWith( + str_starts_with( current($mkdirCustomA->getBox()->getInputPorts())->getVariableValue()->getValue(), "custom_" ) @@ -164,12 +163,12 @@ class TestDirectoriesResolver extends Tester\TestCase Assert::equal([$A], $mkdirCustomB->getChildren()); Assert::count(0, $mkdirCustomB->getDependencies()); Assert::equal(null, $mkdirCustomB->getTestId()); - Assert::true(Strings::startsWith($mkdirCustomB->getBox()->getDirectory(), "custom_custom_")); + Assert::true(str_starts_with($mkdirCustomB->getBox()->getDirectory(), "custom_custom_")); Assert::equal(24, strlen($mkdirCustomB->getBox()->getDirectory())); Assert::equal("mkdir", $mkdirCustomB->getBox()->getType()); Assert::count(1, $mkdirCustomB->getBox()->getInputPorts()); Assert::true( - Strings::startsWith( + str_starts_with( current($mkdirCustomB->getBox()->getInputPorts())->getVariableValue()->getValue(), "custom_" ) @@ -382,7 +381,6 @@ class TestDirectoriesResolver extends Tester\TestCase ); Assert::count(0, $G->getBox()->getOutputPorts()); } - } # Testing methods run diff --git a/tests/helpers/FileStorage.phpt b/tests/helpers/FileStorage.phpt index d1797551b..751698e3c 100644 --- a/tests/helpers/FileStorage.phpt +++ b/tests/helpers/FileStorage.phpt @@ -15,7 +15,6 @@ use App\Model\Entity\UploadedFile; use App\Model\Entity\UploadedPartialFile; use App\Model\Repository\Users; use App\Helpers\TmpFilesHelper; -use Nette\Utils\Strings; use Tester\Assert; /** @@ -66,7 +65,7 @@ class TestFileStorage extends Tester\TestCase $path = "$root/recodex-$ts-$counter"; } while (file_exists($path) || !@mkdir($path)); - if (!is_dir($path) || !Strings::startsWith($path, sys_get_temp_dir())) { + if (!is_dir($path) || !str_starts_with($path, sys_get_temp_dir())) { throw new \Exception("Unable to create tmp dir $path"); } return $path; @@ -74,10 +73,10 @@ class TestFileStorage extends Tester\TestCase private static function rmdirRecursive($path) { - if (!Strings::startsWith($path, sys_get_temp_dir())) { + if (!str_starts_with($path, sys_get_temp_dir())) { throw new \Exception("Must not rmdir something oustise temp dir $path"); } - if (Strings::endsWith($path, '/.') || Strings::endsWith($path, '/..')) { + if (str_ends_with($path, '/.') || str_ends_with($path, '/..')) { return; } if (is_dir($path)) { @@ -151,7 +150,7 @@ class TestFileStorage extends Tester\TestCase $storage = new LocalFileStorage(new TmpFilesHelper($this->tmpDir), [ 'root' => $rootDir ]); foreach ($files as $file => $contents) { - if (Strings::contains($file, '/')) { + if (str_contains($file, '/')) { @mkdir($rootDir . '/' . dirname($file), 0777, true); } $file = "$rootDir/$file"; @@ -824,7 +823,7 @@ class TestFileStorage extends Tester\TestCase $root = $storage->getRootDirectory(); $deleted = $storage->deleteByFilter('foo', function ($file) { - return !Strings::endsWith($file->getStoragePath(), '.txt') + return !str_ends_with($file->getStoragePath(), '.txt') || $file->getSize() < 3; });