Skip to content

Commit

Permalink
Merge branch 'develop' into extend-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Mar 2, 2023
2 parents b1df996 + 6c32cf1 commit 114ec81
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 64 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
id: extcache
uses: shivammathur/cache-extensions@v1
with:
php-version: '8.0'
php-version: '8.1'
extensions: ${{ env.extensions }}
key: ${{ env.key }}

Expand All @@ -42,7 +42,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.0'
php-version: '8.1'
extensions: ${{ env.extensions }}
coverage: none

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"php-parallel-lint/php-parallel-lint": "^1.0",
"meyfa/phpunit-assert-gd": "^2.0.0|^3.0.0",
"dms/phpunit-arraysubset-asserts": "^0.1.0|^0.2.1",
"nunomaduro/larastan": "^2.0.1",
"nunomaduro/larastan": "~2.2.9",
"orchestra/testbench": "^7.1.0"
},
"suggest": {
Expand Down
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -755,16 +755,6 @@ parameters:
count: 1
path: src/Extension/Extendable.php

-
message: "#^Parameter \\#3 \\$replacement of method Illuminate\\\\Support\\\\Collection\\<int\\<0, 1\\>,Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), mixed\\>\\>\\:\\:splice\\(\\) expects array\\<Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\), mixed\\>\\>, array\\{array\\} given\\.$#"
count: 1
path: src/Foundation/Application.php

-
message: "#^Strict comparison using \\=\\=\\= between array\\|null and false will always evaluate to false\\.$#"
count: 1
path: src/Foundation/Exception/Handler.php

-
message: "#^Conditional return type uses subject type TCacheValue which is not part of PHPDoc @template tags\\.$#"
count: 1
Expand Down
4 changes: 2 additions & 2 deletions src/Database/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ class Model extends EloquentModel implements ModelInterface
use \Winter\Storm\Database\Traits\DeferredBinding;

/**
* @var array Behaviors implemented by this model.
* @var string|array|null Extensions implemented by this class.
*/
public $implement;
public $implement = null;

/**
* @var array Make the model's attributes public so behaviors can modify them.
Expand Down
5 changes: 4 additions & 1 deletion src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,13 @@ protected function getRelationValidationValue($relationName)
* Instantiates the validator used by the validation process, depending if the class
* is being used inside or outside of Laravel. Optional connection string to make
* the validator use a different database connection than the default connection.
* @return \Illuminate\Validation\Validator
*
* @return \Illuminate\Contracts\Validation\Validator
* @phpstan-return \Illuminate\Validation\Validator
*/
protected static function makeValidator($data, $rules, $customMessages, $attributeNames, $connection = null)
{
/** @var \Illuminate\Validation\Validator $validator */
$validator = Validator::make($data, $rules, $customMessages, $attributeNames);

if ($connection !== null) {
Expand Down
4 changes: 2 additions & 2 deletions src/Extension/Extendable.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Extendable
use ExtendableTrait;

/**
* @var array Extensions implemented by this class.
* @var string|array|null Extensions implemented by this class.
*/
public $implement;
public $implement = null;

/**
* Constructor
Expand Down
13 changes: 3 additions & 10 deletions src/Extension/ExtendableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*
* @author Alexey Bobkov, Samuel Georges
*/

trait ExtendableTrait
{
/**
Expand Down Expand Up @@ -72,18 +71,12 @@ public function extendableConstruct()
/*
* Apply extensions
*/
if (!$this->implement) {
return;
}

if (is_string($this->implement)) {
$uses = explode(',', $this->implement);
}
elseif (is_array($this->implement)) {
} elseif (is_array($this->implement)) {
$uses = $this->implement;
}
else {
throw new Exception(sprintf('Class %s contains an invalid $implement value', get_class($this)));
} else {
return;
}

foreach ($uses as $use) {
Expand Down
17 changes: 16 additions & 1 deletion src/Filesystem/Filesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,21 @@ public function localToPublic(string $path): ?string
return $result;
}

/**
* Returns whether the file path is an absolute path.
* @see Symfony\Component\Filesystem\Filesystem::isAbsolutePath()
*/
public function isAbsolutePath(string $file): bool
{
return '' !== $file && (strspn($file, '/\\', 0, 1)
|| (\strlen($file) > 3 && ctype_alpha($file[0])
&& ':' === $file[1]
&& strspn($file, '/\\', 2, 1)
)
|| null !== parse_url($file, \PHP_URL_SCHEME)
);
}

/**
* Determines if the given path is a local path.
*
Expand Down Expand Up @@ -231,7 +246,7 @@ public function isPathSymbol(string $path): bool
* @param string $path
* @param string $contents
* @param bool|int $lock
* @return bool|int
* @return int|false
*/
public function put($path, $contents, $lock = false)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function make($abstract, array $parameters = [])
*/
public function before($callback)
{
$this['router']->before($callback);
$this->make('router')->before($callback);
}

/**
Expand All @@ -323,7 +323,7 @@ public function before($callback)
*/
public function after($callback)
{
$this['router']->after($callback);
$this->make('router')->after($callback);
}

/**
Expand Down
22 changes: 5 additions & 17 deletions src/Foundation/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
class Kernel extends HttpKernel
{
/**
* The bootstrap classes for the application.
*
* @var string[]
* {@inheritDoc}
*/
protected $bootstrappers = [
\Winter\Storm\Foundation\Bootstrap\RegisterClassLoader::class,
Expand All @@ -22,9 +20,7 @@ class Kernel extends HttpKernel
];

/**
* The application's global HTTP middleware stack.
*
* @var array
* {@inheritDoc}
*/
protected $middleware = [
\Winter\Storm\Foundation\Http\Middleware\CheckForTrustedHost::class,
Expand All @@ -33,9 +29,7 @@ class Kernel extends HttpKernel
];

/**
* The application's route middleware.
*
* @var array
* {@inheritDoc}
*/
protected $routeMiddleware = [
// 'auth' => \Illuminate\Auth\Middleware\Authenticate::class,
Expand All @@ -47,9 +41,7 @@ class Kernel extends HttpKernel
];

/**
* The application's route middleware groups.
*
* @var array
* {@inheritDoc}
*/
protected $middlewareGroups = [
'web' => [
Expand All @@ -67,11 +59,7 @@ class Kernel extends HttpKernel
];

/**
* The priority-sorted list of middleware.
*
* Forces the listed middleware to always be in the given order.
*
* @var string[]
* {@inheritDoc}
*/
protected $middlewarePriority = [
\Illuminate\Session\Middleware\StartSession::class,
Expand Down
4 changes: 4 additions & 0 deletions src/Html/FormBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ public function input(string $type, ?string $name = null, ?string $value = null,
// when creating the HTML element. Then, we will return the entire input.
$merge = compact('type', 'value', 'id');

if ($id === "") {
unset($merge['id']);
}

$options = array_filter(array_merge($options, $merge), function ($item) {
return !is_null($item);
});
Expand Down
4 changes: 2 additions & 2 deletions src/Network/Http.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class Http
/**
* @var array cURL Options.
*/
public $requestOptions;
public $requestOptions = [];

/**
* @var array Request data.
Expand Down Expand Up @@ -280,7 +280,7 @@ public function send()
curl_setopt($curl, CURLOPT_MAXREDIRS, $this->maxRedirects);
}

if ($this->requestOptions && is_array($this->requestOptions)) {
if (count($this->requestOptions)) {
curl_setopt_array($curl, $this->requestOptions);
}

Expand Down
13 changes: 10 additions & 3 deletions src/Support/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ class_alias($alias, $class);
*/
protected function resolvePath(string $path): string
{
if (!Str::startsWith($path, ['/', '\\', $this->basePath . DIRECTORY_SEPARATOR])) {
if (!$this->files->isAbsolutePath($path)) {
$path = $this->basePath . DIRECTORY_SEPARATOR . $path;
}
return $path;
Expand Down Expand Up @@ -228,10 +228,17 @@ public function build(): void

/**
* Add a namespace prefix to the autoloader
*
* @param string $namespacePrefix The namespace prefix for this package
* @param string $path The path to this package, either relative to the base path or absolute
*/
public function autoloadPackage(string $namespacePrefix, string $relativePath): void
public function autoloadPackage(string $namespacePrefix, string $path): void
{
$this->autoloadedPackages[ltrim(Str::lower($namespacePrefix), '\\')] = $relativePath;
// Normalize the path to an absolute path and then attempt to use the relative path
// if the path is contained within the basePath
$path = Str::after($this->resolvePath($path), $this->basePath . DIRECTORY_SEPARATOR);

$this->autoloadedPackages[ltrim(Str::lower($namespacePrefix), '\\')] = $path;

// Ensure packages are sorted by length of the prefix to prevent a greedier prefix
// from being matched first when attempting to autoload a class
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Facades/DB.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* @method static \Doctrine\DBAL\Driver\PDOConnection getPdo()
* @method static \Illuminate\Database\ConnectionInterface connection(string $name = null)
* @method static \Illuminate\Database\Connection connection(string $name = null)
* @method static \Winter\Storm\Database\QueryBuilder table(string $table, string $as = null)
* @method static \Illuminate\Database\Query\Expression raw($value)
* @method static array getQueryLog()
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Facades/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

/**
* @method static bool exists(string $path)
* @method static string get(string $path, bool $lock)
* @method static string get(string $path, bool $lock = false)
* @method static string sharedGet(string $path)
* @method static mixed getRequire(string $path)
* @method static mixed requireOnce(string $file)
Expand Down
4 changes: 3 additions & 1 deletion src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function e($value, $doubleEncode = false)
*/
function trans($id = null, $parameters = [], $locale = null)
{
return app('translator')->trans($id, $parameters, $locale);
/** @var \Winter\Storm\Translation\Translator $translator */
$translator = app('translator');
return $translator->trans($id, $parameters, $locale);
}
}

Expand Down
8 changes: 0 additions & 8 deletions tests/Extension/ExtendableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,6 @@ public function testAccessingProtectedStaticMethod()
echo ExtendableTestExampleExtendableClass::protectedMars();
}

public function testInvalidImplementValue()
{
$this->expectException(Exception::class);
$this->expectExceptionMessage('Class ExtendableTestInvalidExtendableClass contains an invalid $implement value');

$result = new ExtendableTestInvalidExtendableClass;
}

public function testSoftImplementFake()
{
$result = $this->mockClassLoader(ExtendableTestExampleExtendableSoftImplementFakeClass::class);
Expand Down
39 changes: 39 additions & 0 deletions tests/Filesystem/FilesystemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

use Winter\Storm\Filesystem\Filesystem;

/**
*
*/
class FilesystemTest extends TestCase
{
protected ?Filesystem $filesystem = null;

public function setUp(): void
{
$this->filesystem = new Filesystem();
}

/**
* @dataProvider providePathsForIsAbsolutePath
* @see Symfony\Component\Filesystem\Tests\FilesystemTest::testIsAbsolutePath
*/
public function testIsAbsolutePath($path, $expectedResult)
{
$result = $this->filesystem->isAbsolutePath($path);

$this->assertEquals($expectedResult, $result);
}

public function providePathsForIsAbsolutePath()
{
return [
['/var/lib', true],
['c:\\\\var\\lib', true],
['\\var\\lib', true],
['var/lib', false],
['../var/lib', false],
['', false],
];
}
}
Loading

0 comments on commit 114ec81

Please sign in to comment.