Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code analysis for Laravel 9 branch #64

Merged
merged 120 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
120 commits
Select commit Hold shift + click to select a range
66f1d2a
Add Larastan, initial code analysis tweaks
bennothommo Dec 14, 2021
7c0817e
Merge branch 'wip/0.2' into wip/1.2-code-analysis
bennothommo Dec 17, 2021
0226ffe
Fix code blocks and signatures in Halcyon
bennothommo Dec 17, 2021
ccdf514
Fix default config namespaces not loading
bennothommo Dec 17, 2021
68f7ab3
Further fixes to docblocks and signatures
bennothommo Dec 17, 2021
c973318
Documenting magic methods and properties of Auth models
bennothommo Dec 17, 2021
c99be36
Initial work on strict typing and return types
bennothommo Dec 17, 2021
cc3b023
Apply suggestions from code review
bennothommo Dec 18, 2021
26f6b79
Merge remote-tracking branch 'origin/wip/1.2' into wip/1.2-code-analysis
bennothommo Dec 19, 2021
1968d06
Set strict types on Argon
bennothommo Dec 20, 2021
cb1b0b3
Fix comment on makeFilePath method in DbDatasource
bennothommo Dec 20, 2021
3fed80a
Use proper exception for insert, update docs
bennothommo Dec 20, 2021
78af61f
Fix code smell
bennothommo Dec 20, 2021
d7dd396
Model/Pivot constructor changes.
bennothommo Dec 20, 2021
6c96d97
Adjust users table migration
bennothommo Dec 20, 2021
b2f103b
Improve docblocks in Auth module
bennothommo Dec 20, 2021
4a4755a
Add database migration paths for PHPStan
bennothommo Dec 20, 2021
2956fc4
Extend Laravel Config repo in our own repo
bennothommo Dec 20, 2021
d628e26
Ignore Auth Manager in analysis
bennothommo Dec 20, 2021
cfd2e4a
Re-add ApplicationException use case
bennothommo Dec 20, 2021
233f8b6
Inherit docs
bennothommo Dec 20, 2021
773f02f
Fix return types in dispatcher
bennothommo Dec 20, 2021
3fc1902
Fix docblocks and signatures in Exception module
bennothommo Dec 20, 2021
a60425f
Fix tests
bennothommo Dec 20, 2021
df0061d
Adjust docs and signatures for Extendable trait
bennothommo Dec 20, 2021
1bd7fb2
Return null if no default datasource is set
bennothommo Dec 20, 2021
c7339d9
Fix signatures and docblocks of Filesystem module
bennothommo Dec 20, 2021
efd145f
Fix Foundation module docblocks and signatures
bennothommo Dec 20, 2021
38819df
WIP FormBuilder
bennothommo Dec 20, 2021
1a46e9e
WIP Html module analysis
bennothommo Dec 20, 2021
6f90d90
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Feb 23, 2022
33328e4
Update Composer deps, small tweaks
bennothommo Feb 23, 2022
0a71452
Add class comment
bennothommo Feb 24, 2022
b1fd554
Fix Stan issues in Translator
bennothommo Feb 24, 2022
d174113
Fix Validation and Support PHPStan issues
bennothommo Feb 24, 2022
4cf0199
Fix Router PHPStan issues
bennothommo Feb 24, 2022
6521824
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Feb 24, 2022
3fe31df
Add Event facade methods
bennothommo Feb 24, 2022
ff29e6a
Fix Parse PHPStan issues
bennothommo Feb 24, 2022
6ea0cf9
Fix Network PHPStan issues
bennothommo Feb 24, 2022
ee06185
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Feb 24, 2022
0899bb8
Fix return type of fired events
bennothommo Feb 24, 2022
86e8aa9
Fix minor issue in MailManager
bennothommo Feb 24, 2022
f87d594
WIP Mailer fixes
bennothommo Feb 24, 2022
2ef3234
Fix HTML PHPStand issues
bennothommo Feb 24, 2022
b679f20
Fix unit tests - Mail ones are not passing now, but pass on main branch
bennothommo Feb 24, 2022
3b7d4f2
Implement changes from Luke's review
bennothommo Feb 25, 2022
2370eaa
Finalise Mail PHPStan fixes
bennothommo Feb 25, 2022
ba6617a
Merge remote-tracking branch 'origin/wip/1.2' into wip/1.2-code-analysis
bennothommo Feb 25, 2022
4f1db25
Fix Command PHPStan issues
bennothommo Feb 25, 2022
0fd415d
Merge remote-tracking branch 'origin/wip/1.2' into wip/1.2-code-analysis
bennothommo Feb 25, 2022
ab137a1
Tweak extendable trait
bennothommo Feb 25, 2022
7918a13
WIP fixes of Database PHPStan issues
bennothommo Feb 25, 2022
35b36b7
Defensive coding tweak
bennothommo Feb 26, 2022
5681961
Merge remote-tracking branch 'origin/wip/1.2' into wip/1.2-code-analysis
bennothommo Feb 28, 2022
6fb9ca9
Adjust Command logic path for input type parsing
bennothommo Feb 28, 2022
bfcc68f
Fix some issues picked up by PHPStan when global scan is used
bennothommo Feb 28, 2022
9891101
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Apr 14, 2022
e042c0c
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Apr 29, 2022
15ed858
Fix tests
bennothommo Apr 29, 2022
f9cc4fe
Synchronise docblocks
bennothommo May 3, 2022
3786591
Drop unnecessary overwrite in hasOne relation.
bennothommo May 3, 2022
f79eac4
Simplify "key:generate" command overwrite
bennothommo May 3, 2022
3697094
Tweak checks for URL generator values
bennothommo May 3, 2022
e3f2bac
Refactor database relations.
bennothommo May 3, 2022
cf251aa
Make Argon extend Illuminate's Carbon wrapper
bennothommo May 3, 2022
6805eb1
Numerous fixes to docblocks and signatures
bennothommo May 3, 2022
298fea5
Exclude some errors that are not helping
bennothommo May 3, 2022
206edcd
Final pass of code analysis tweaks
bennothommo May 5, 2022
82a7996
Fix sortable constant reference and test
bennothommo May 5, 2022
03e95b6
Convert private methods to protected in Section Parser
bennothommo May 5, 2022
51cec2f
Change return type in Argon
bennothommo May 11, 2022
44f6f38
Synchronise Pivot model with Laravel 9
bennothommo May 13, 2022
6a9022e
Add MorphPivot support
bennothommo May 13, 2022
650eab5
Update src/Database/Attach/File.php
bennothommo May 14, 2022
1ba308a
Update src/Console/Command.php
bennothommo May 22, 2022
5645a5b
Update src/Database/MorphPivot.php
bennothommo May 22, 2022
a200219
Add type hints to all File attachment methods
bennothommo May 22, 2022
02b5b98
Add type hints
bennothommo May 22, 2022
a780758
Make the Pivot use the AsPivot trait, add parent accessor
bennothommo May 22, 2022
e8f880f
Update src/Database/Behaviors/Purgeable.php
bennothommo May 22, 2022
bebff18
Update src/Database/Behaviors/Sortable.php
bennothommo May 22, 2022
6356bd2
Update src/Filesystem/Filesystem.php
LukeTowers May 22, 2022
faf29f9
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Jun 26, 2022
361e17e
Remove relation traits that have been moved to concerns
bennothommo Jun 26, 2022
d07a9e6
Update all facade use cases to use full facade class
bennothommo Jun 26, 2022
6d55a77
Add options docs for Zip class, fix BC break
bennothommo Jun 26, 2022
1ef7cfc
Re-add default value
bennothommo Jun 26, 2022
1154159
Remove overwritten definition for resolver
bennothommo Jun 26, 2022
1124812
Merge branch 'wip/1.2' into wip/1.2-code-analysis
bennothommo Jun 29, 2022
05698c8
Fix moved class names in aliases
bennothommo Jun 29, 2022
15b359b
Add MorphPivot test cases
bennothommo Jun 29, 2022
e374dce
Fix constructor for MorphToPivot
bennothommo Jun 29, 2022
c168945
Revert hour value change
bennothommo Jun 29, 2022
a8da8cd
Correct docblock return
bennothommo Jun 29, 2022
08b75fc
Match PHPCS config from main repo
bennothommo Jun 30, 2022
0ec2ac5
Use lang path in Translator registration
bennothommo Jun 30, 2022
892b890
Fix possible BC break, cleanup for PHPStan
bennothommo Jun 30, 2022
4301383
Code tidying
bennothommo Jun 30, 2022
cbec8d9
Try out @phpstan-property definitions to fix remaining issues
bennothommo Jun 30, 2022
a02f94e
Docs and commenting changes to fix a whole slew of issues
bennothommo Jul 1, 2022
79761b5
Generate baseline
bennothommo Jul 1, 2022
8ac383f
Allow pivot model to be provided to MorphTo relations
bennothommo Jul 1, 2022
af29492
Fix test, allow namespaced files in tests folder
bennothommo Jul 1, 2022
ee73adf
Move tests namespace into autoload-dev
bennothommo Jul 1, 2022
76835e6
Add automated PHPStan test, tweak PHPUnit test
bennothommo Jul 1, 2022
9f57231
Replace missing matrix vars
bennothommo Jul 1, 2022
6273bc6
Fix Markdown parser class name storage and use
bennothommo Jul 1, 2022
c096e92
Remove use of Eloquent facade in down migrations
bennothommo Jul 1, 2022
696d4a7
Convert all type hints to PHPDocs to maintain BC
bennothommo Jul 1, 2022
45765b5
Small tweak
bennothommo Jul 1, 2022
67a3b64
Ensure morph to supports deferred records and constraints
bennothommo Jul 1, 2022
8951f40
Remove fixed errors from baseline
bennothommo Jul 1, 2022
3558833
Allow CSRF token and session key to be null
bennothommo Jul 1, 2022
ba709ce
Fix return type
bennothommo Jul 1, 2022
cb93b80
Ignore lines in PHPStan - it can't seem to work out the relations here
bennothommo Jul 1, 2022
7a85594
Update src/Database/Relations/Concerns/DeferOneOrMany.php
bennothommo Jul 1, 2022
784ab77
Update src/Database/Relations/Concerns/DeferOneOrMany.php
bennothommo Jul 1, 2022
fe190c6
Remove return type missed in last pass
bennothommo Jul 2, 2022
422e58e
Change to Str call
bennothommo Jul 2, 2022
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
Prev Previous commit
Next Next commit
WIP fixes of Database PHPStan issues
  • Loading branch information
bennothommo committed Feb 25, 2022
commit 7918a1396a047a570937335f0b2f998c8767789a
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ parameters:
level: 5
excludePaths:
- src/Auth/Manager.php
- src/Database/Behaviors/Purgeable.php
databaseMigrationsPath:
- src/Auth/Migrations
- src/Database/Migrations
Expand Down
101 changes: 54 additions & 47 deletions src/Database/Attach/File.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
<?php namespace Winter\Storm\Database\Attach;

use Log;
use Cache;
use Storage;
use File as FileHelper;
use Exception;
use Winter\Storm\Network\Http;
use Winter\Storm\Database\Model;
use Winter\Storm\Support\Facades\File as FileHelper;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Storage;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\File\File as FileObj;
use Exception;

/**
* File attachment model
*
* @author Alexey Bobkov, Samuel Georges
*
* @property string $file_name The name of the file
* @property int $file_size The size of the file
* @property string $content_type The MIME type of the file
* @property string $disk_name The generated disk name of the file
*/
class File extends Model
{
Expand All @@ -25,14 +30,14 @@ class File extends Model
protected $table = 'files';

/**
* Relations
* @var array Relations
*/
public $morphTo = [
'attachment' => [],
];

/**
* @var array The attributes that are mass assignable.
* @var string[] The attributes that are mass assignable.
*/
protected $fillable = [
'file_name',
Expand All @@ -47,12 +52,12 @@ class File extends Model
];

/**
* @var array The attributes that aren't mass assignable.
* @var string[] The attributes that aren't mass assignable.
*/
protected $guarded = [];

/**
* @var array Known image extensions.
* @var string[] Known image extensions.
*/
public static $imageExtensions = ['jpg', 'jpeg', 'png', 'gif', 'webp'];

Expand Down Expand Up @@ -93,14 +98,10 @@ class File extends Model

/**
* Creates a file object from a file an uploaded file.
* @param Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
* @param \Symfony\Component\HttpFoundation\File\UploadedFile $uploadedFile
*/
public function fromPost($uploadedFile)
bennothommo marked this conversation as resolved.
Show resolved Hide resolved
{
if ($uploadedFile === null) {
return;
}

LukeTowers marked this conversation as resolved.
Show resolved Hide resolved
$this->file_name = $uploadedFile->getClientOriginalName();
$this->file_size = $uploadedFile->getSize();
$this->content_type = $uploadedFile->getMimeType();
Expand Down Expand Up @@ -141,17 +142,13 @@ public function fromFile($filePath)
/**
* Creates a file object from raw data.
*
* @param $data string Raw data
* @param $filename string Filename
* @param string $data Raw data
* @param string $filename Filename
*
* @return $this
*/
public function fromData($data, $filename)
{
if ($data === null) {
return;
}
bennothommo marked this conversation as resolved.
Show resolved Hide resolved

LukeTowers marked this conversation as resolved.
Show resolved Hide resolved
$tempPath = temp_path($filename);
FileHelper::put($tempPath, $data);

Expand All @@ -163,8 +160,9 @@ public function fromData($data, $filename)

/**
* Creates a file object from url
* @param $url string URL
* @param $filename string Filename
*
* @param string $url URL to the file
* @param string|null $filename The filename
* @return $this
*/
public function fromUrl($url, $filename = null)
Expand Down Expand Up @@ -230,7 +228,10 @@ public function setDataAttribute($value)

/**
* Helper attribute for get image width.
* @return string
*
* Returns `null` if this file is not an image.
*
* @return string|null
*/
public function getWidthAttribute()
{
Expand All @@ -239,11 +240,16 @@ public function getWidthAttribute()

return $dimensions[0];
}

return null;
}

/**
* Helper attribute for get image height.
* @return string
*
* Returns `null` if this file is not an image.
*
* @return string|null
*/
public function getHeightAttribute()
{
Expand All @@ -252,6 +258,8 @@ public function getHeightAttribute()

return $dimensions[1];
}

return null;
}

/**
Expand All @@ -272,7 +280,7 @@ public function getSizeAttribute()
*
* @param string $disposition The Content-Disposition to set, defaults to inline
* @param bool $returnResponse Defaults to false, returns a Response object instead of directly outputting to the browser
* @return Response | void
* @return \Illuminate\Http\Response|void
*/
public function output($disposition = 'inline', $returnResponse = false)
{
Expand All @@ -286,10 +294,10 @@ public function output($disposition = 'inline', $returnResponse = false)

if ($returnResponse) {
return $response;
} else {
$response->sendHeaders();
$response->sendContent();
}

$response->sendHeaders();
$response->sendContent();
}

/**
Expand All @@ -307,7 +315,7 @@ public function output($disposition = 'inline', $returnResponse = false)
* 'disposition' => 'inline',
* ]
* @param bool $returnResponse Defaults to false, returns a Response object instead of directly outputting to the browser
* @return Response | void
* @return \Illuminate\Http\Response|void
*/
public function outputThumb($width, $height, $options = [], $returnResponse = false)
{
Expand All @@ -327,10 +335,10 @@ public function outputThumb($width, $height, $options = [], $returnResponse = fa

if ($returnResponse) {
return $response;
} else {
$response->sendHeaders();
$response->sendContent();
}

$response->sendHeaders();
$response->sendContent();
}

//
Expand Down Expand Up @@ -739,7 +747,7 @@ protected function getDiskName()
$ext = $this->data->guessExtension();
}

$name = str_replace('.', '', uniqid(null, true));
$name = str_replace('.', '', uniqid('', true));

return $this->disk_name = !empty($ext) ? $name.'.'.$ext : $name;
}
Expand Down Expand Up @@ -786,10 +794,9 @@ protected function putFile($sourcePath, $destinationFileName = null)
*/
if (
!FileHelper::isDirectory($destinationPath) &&
!FileHelper::makeDirectory($destinationPath, 0777, true, true) &&
!FileHelper::isDirectory($destinationPath)
!FileHelper::makeDirectory($destinationPath, 0777, true, true)
LukeTowers marked this conversation as resolved.
Show resolved Hide resolved
) {
trigger_error(error_get_last(), E_USER_WARNING);
trigger_error(error_get_last()['message'], E_USER_WARNING);
}

return FileHelper::copy($sourcePath, $destinationPath . $destinationFileName);
Expand Down Expand Up @@ -818,7 +825,7 @@ protected function deleteFile($fileName = null)

/**
* Check file exists on storage device.
* @return void
* @return bool
*/
protected function hasFile($fileName = null)
{
Expand Down Expand Up @@ -866,14 +873,13 @@ protected function deleteEmptyDirectory($dir = null)

/**
* Returns true if a directory contains no files.
* @return void
*
* @param string $dir The path to the directory.
*
* @return bool|null
bennothommo marked this conversation as resolved.
Show resolved Hide resolved
*/
protected function isDirectoryEmpty($dir)
{
if (!$dir) {
return null;
}

bennothommo marked this conversation as resolved.
Show resolved Hide resolved
return count($this->storageCmd('allFiles', $dir)) === 0;
}

Expand Down Expand Up @@ -933,7 +939,8 @@ protected function copyLocalToStorage($localPath, $storagePath)

/**
* Returns the maximum size of an uploaded file as configured in php.ini
* @return int The maximum size of an uploaded file in kilobytes
*
* @return float The maximum size of an uploaded file in kilobytes (rounded)
*/
public static function getMaxFilesize()
{
Expand Down Expand Up @@ -980,7 +987,8 @@ public function getTempPath()

/**
* Returns the storage disk the file is stored on
* @return FilesystemAdapter
*
* @return \Illuminate\Filesystem\FilesystemAdapter
*/
public function getDisk()
{
Expand All @@ -999,9 +1007,8 @@ protected function isLocalStorage()
/**
* Generates a partition for the file.
* return /ABC/DE1/234 for an name of ABCDE1234.
* @param Attachment $attachment
* @param string $styleName
* @return mixed
*
* @return string
*/
protected function getPartitionDirectory()
{
Expand Down
22 changes: 9 additions & 13 deletions src/Database/Behaviors/Purgeable.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?php namespace Winter\Storm\Database\Behaviors;

/**
* @deprecated 1.2.0. We recommend using the \Winter\Storm\Database\Traits\Purgeable trait instead.
*/
LukeTowers marked this conversation as resolved.
Show resolved Hide resolved
bennothommo marked this conversation as resolved.
Show resolved Hide resolved
class Purgeable extends \Winter\Storm\Extension\ExtensionBase
{
/**
* @var array List of attribute names which should not be saved to the database.
*/
public $purgeable = [];

/**
* Model to purge.
*
* @var \Winter\Storm\Database\Model
* @property array $purgeable
*/
protected $model;

Expand Down Expand Up @@ -51,7 +50,7 @@ public function bootPurgeable()
/**
* Adds an attribute to the purgeable attributes list
* @param array|string|null $attributes
* @return $this
* @return \Winter\Storm\Database\Model
*/
public function addPurgeable($attributes = null)
{
Expand All @@ -64,7 +63,7 @@ public function addPurgeable($attributes = null)

/**
* Removes purged attributes from the dataset, used before saving.
* @param $attributes mixed Attribute(s) to purge, if unspecified, $purgable property is used
* @param string|array|null $attributesToPurge Attribute(s) to purge. If unspecified, $purgable property is used
* @return array Current attribute set
*/
public function purgeAttributes($attributesToPurge = null)
Expand All @@ -80,12 +79,7 @@ public function purgeAttributes($attributesToPurge = null)
$cleanAttributes = array_diff_key($attributes, array_flip($purgeable));
$originalAttributes = array_diff_key($attributes, $cleanAttributes);

if (is_array($this->originalPurgeableValues)) {
$this->originalPurgeableValues = array_merge($this->originalPurgeableValues, $originalAttributes);
}
else {
$this->originalPurgeableValues = $originalAttributes;
}
$this->originalPurgeableValues = array_merge($this->originalPurgeableValues, $originalAttributes);
LukeTowers marked this conversation as resolved.
Show resolved Hide resolved

return $this->model->attributes = $cleanAttributes;
}
Expand Down Expand Up @@ -116,6 +110,8 @@ public function getOriginalPurgeValue($attribute)

/**
* Restores the original values of any purged attributes.
*
* @return \Winter\Storm\Database\Model
*/
public function restorePurgedValues()
{
Expand Down
1 change: 1 addition & 0 deletions src/Database/Behaviors/Sortable.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*
* const SORT_ORDER = 'my_sort_order';
*
* @deprecated 1.2.0. We recommend using the \Winter\Storm\Database\Traits\Sortable trait instead.
LukeTowers marked this conversation as resolved.
Show resolved Hide resolved
bennothommo marked this conversation as resolved.
Show resolved Hide resolved
*/
class Sortable extends ExtensionBase
{
Expand Down
Loading