Skip to content

Commit 828ef47

Browse files
committed
Laravel 10
1 parent 9b9fffc commit 828ef47

File tree

11 files changed

+51
-70
lines changed

11 files changed

+51
-70
lines changed

composer.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
}
99
],
1010
"require": {
11-
"laravel/framework": "^9.0",
11+
"laravel/framework": "^9.0|^10.0",
1212
"ext-json": "*"
1313
},
1414
"autoload": {
@@ -17,8 +17,9 @@
1717
}
1818
},
1919
"require-dev": {
20-
"phpunit/phpunit": "^9.5",
21-
"friendsofphp/php-cs-fixer": "^3.0"
20+
"phpunit/phpunit": "^10.0",
21+
"brainmaestro/composer-git-hooks": "dev-master",
22+
"laravel/pint": "^1.5"
2223
},
2324
"extra": {
2425
"laravel": {
@@ -50,9 +51,9 @@
5051
"cghooks update"
5152
],
5253
"cghooks": "vendor/bin/cghooks",
53-
"check-style": "php-cs-fixer fix --using-cache=no --diff --dry-run --ansi",
54-
"fix-style": "php-cs-fixer fix --using-cache=no --ansi",
55-
"test": "vendor/bin/phpunit --colors=always --testdox"
54+
"check-style": "vendor/bin/pint --test",
55+
"fix-style": "vendor/bin/pint",
56+
"test": "vendor/bin/phpunit --colors=always"
5657
},
5758
"scripts-descriptions": {
5859
"test": "Run all tests.",

phpunit.xml

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
bootstrap="vendor/autoload.php"
5-
colors="true"
6-
convertErrorsToExceptions="true"
7-
convertNoticesToExceptions="true"
8-
convertWarningsToExceptions="true"
9-
processIsolation="false"
10-
stopOnFailure="false">
11-
<testsuites>
12-
<testsuite name="Application Test Suite">
13-
<directory>./tests/</directory>
14-
</testsuite>
15-
</testsuites>
16-
<filter>
17-
<whitelist>
18-
<directory suffix=".php">src/</directory>
19-
<exclude>
20-
<directory suffix="Exception.php">src/</directory>
21-
</exclude>
22-
</whitelist>
23-
</filter>
24-
<php>
25-
<const name="PHPUNIT_RUNNING" value="true" />
26-
</php>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">src/</directory>
6+
</include>
7+
<exclude>
8+
<directory suffix="Exception.php">src/</directory>
9+
</exclude>
10+
</coverage>
11+
<testsuites>
12+
<testsuite name="Application Test Suite">
13+
<directory>./tests/</directory>
14+
</testsuite>
15+
</testsuites>
16+
<php>
17+
<const name="PHPUNIT_RUNNING" value="true"/>
18+
</php>
2719
</phpunit>

src/Events/FileDeleted.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ class FileDeleted
88
{
99
public UploadedFile $file;
1010

11-
/**
12-
* @param \Illuminate\Http\UploadedFile $file
13-
*/
1411
public function __construct(UploadedFile $file)
1512
{
1613
$this->file = $file;

src/Events/FileDeleting.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ class FileDeleting
1010

1111
/**
1212
* Create a new event instance.
13-
*
14-
* @param \Illuminate\Http\UploadedFile $file
1513
*/
1614
public function __construct(UploadedFile $file)
1715
{

src/Events/FileUploaded.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
class FileUploaded
1010
{
1111
public UploadedFile $file;
12+
1213
public Response $response;
14+
1315
public Strategy $strategy;
1416

15-
/**
16-
* @param \Illuminate\Http\UploadedFile $file
17-
* @param \Overtrue\LaravelUploader\Response $response
18-
* @param \Overtrue\LaravelUploader\Strategy $strategy
19-
*/
2017
public function __construct(UploadedFile $file, Response $response, Strategy $strategy)
2118
{
2219
$this->file = $file;

src/Events/FileUploading.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ class FileUploading
88
{
99
public UploadedFile $file;
1010

11-
/**
12-
* @param \Illuminate\Http\UploadedFile $file
13-
*/
1411
public function __construct(UploadedFile $file)
1512
{
1613
$this->file = $file;

src/Http/Controllers/UploadController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class UploadController extends BaseController
1111
/**
1212
* Handle file upload.
1313
*
14-
* @param Request $request
1514
*
1615
* @return \Overtrue\LaravelUploader\Response
1716
*/

src/LaravelUploader.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,11 @@
88
class LaravelUploader extends Facade
99
{
1010
/**
11-
* @param array $options
12-
*
1311
* @throws BindingResolutionException
1412
*/
1513
public static function routes(array $options = [])
1614
{
17-
if (!self::$app->routesAreCached()) {
15+
if (! self::$app->routesAreCached()) {
1816
self::$app->make('router')->post(
1917
'files/upload',
2018
\array_merge([

src/Response.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@
1010
class Response implements Jsonable, Arrayable
1111
{
1212
public string $disk;
13+
1314
public string $path;
15+
1416
public ?string $mime;
17+
1518
public string $size;
19+
1620
public string $url;
21+
1722
public string $relativeUrl;
23+
1824
public string $filename;
25+
1926
public string $extension;
27+
2028
public string $originalName;
29+
2130
public UploadedFile $file;
31+
2232
public Strategy $strategy;
2333

2434
/**
25-
* @param string $path
26-
* @param \Overtrue\LaravelUploader\Strategy $strategy
27-
* @param \Illuminate\Http\UploadedFile $file
35+
* @param \Overtrue\LaravelUploader\Strategy $strategy
2836
*/
2937
public function __construct(string $path, Strategy $strategy, UploadedFile $file)
3038
{
@@ -54,8 +62,7 @@ public function __construct(string $path, Strategy $strategy, UploadedFile $file
5462
}
5563

5664
/**
57-
* @param int $options
58-
*
65+
* @param int $options
5966
* @return string
6067
*/
6168
public function toJson($options = 0)

src/Strategy.php

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@
1212
class Strategy
1313
{
1414
protected string $disk;
15+
1516
protected string $directory;
17+
1618
protected array $mimes = [];
19+
1720
protected string $name;
21+
1822
protected int $maxSize = 0;
23+
1924
protected string $filenameType;
25+
2026
protected UploadedFile $file;
2127

22-
/**
23-
* @param array $config
24-
* @param UploadedFile $file
25-
*/
2628
public function __construct(array $config, UploadedFile $file)
2729
{
2830
$config = new Fluent($config);
@@ -117,18 +119,16 @@ public function isValidSize()
117119

118120
public function validate()
119121
{
120-
if (!$this->isValidMime()) {
122+
if (! $this->isValidMime()) {
121123
\abort(422, \sprintf('Invalid mime "%s".', $this->file->getClientMimeType()));
122124
}
123125

124-
if (!$this->isValidSize()) {
126+
if (! $this->isValidSize()) {
125127
\abort(422, \sprintf('File has too large size("%s").', $this->file->getSize()));
126128
}
127129
}
128130

129131
/**
130-
* @param array $options
131-
*
132132
* @return \Overtrue\LaravelUploader\Response
133133
*/
134134
public function upload(array $options = [])
@@ -156,7 +156,6 @@ public function upload(array $options = [])
156156
/**
157157
* Replace date variable in dir path.
158158
*
159-
* @param string $dir
160159
*
161160
* @return string
162161
*/
@@ -176,23 +175,22 @@ protected function formatDirectory(string $dir)
176175

177176
/**
178177
* @param mixed $humanFileSize
179-
*
180178
* @return int
181179
*/
182180
protected function filesize2bytes($humanFileSize)
183181
{
184-
$bytesUnits = array(
182+
$bytesUnits = [
185183
'K' => 1024,
186184
'M' => 1024 * 1024,
187185
'G' => 1024 * 1024 * 1024,
188186
'T' => 1024 * 1024 * 1024 * 1024,
189187
'P' => 1024 * 1024 * 1024 * 1024 * 1024,
190-
);
188+
];
191189

192190
$bytes = floatval($humanFileSize);
193191

194192
if (preg_match('~([KMGTP])$~si', rtrim($humanFileSize, 'B'), $matches)
195-
&& !empty($bytesUnits[\strtoupper($matches[1])])) {
193+
&& ! empty($bytesUnits[\strtoupper($matches[1])])) {
196194
$bytes *= $bytesUnits[\strtoupper($matches[1])];
197195
}
198196

0 commit comments

Comments
 (0)