Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/V1Module/presenters/UploadedFilesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions app/V1Module/presenters/base/BasePresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/V1Module/security/ACLModuleBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions app/V1Module/security/AccessManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
Expand Down
4 changes: 1 addition & 3 deletions app/V1Module/security/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
5 changes: 2 additions & 3 deletions app/commands/DoctrineFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 . '"';
}
}
Expand Down
3 changes: 1 addition & 2 deletions app/commands/runtimes/RuntimeImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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).");
}
Expand Down
5 changes: 2 additions & 3 deletions app/helpers/BasicAuthHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/
class BasicAuthHelper
{

/**
* Extracts the username and password from the Authorization header of the HTTP request.
* @param IRequest $req HTTP request
Expand All @@ -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)"
);
Expand Down
3 changes: 0 additions & 3 deletions app/helpers/ExerciseConfig/Pipeline/Box/Boxes/ExtractBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 1 addition & 3 deletions app/helpers/ExerciseConfig/Pipeline/Box/Boxes/JvmRunBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions app/helpers/ExerciseConfig/Variables/Variable.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}


Expand Down
6 changes: 2 additions & 4 deletions app/helpers/FileStorage/File/ArchivedImmutableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
}
Expand Down
6 changes: 2 additions & 4 deletions app/helpers/FileStorage/File/LocalImmutableFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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.",
Expand Down
23 changes: 10 additions & 13 deletions app/helpers/FileStorage/LocalStorage/LocalFileStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Helpers\TmpFilesHelper;
use Nette\Utils\Arrays;
use Nette\Utils\Strings;
use Nette\SmartObject;
use ZipArchive;
use FilesystemIterator;
Expand Down Expand Up @@ -33,7 +32,7 @@ class LocalFileStorage implements IFileStorage

protected $rootDirectory;

public function getRootDirectory(): string
public function getRootDirectory(): ?string
{
return $this->rootDirectory;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
Loading