Skip to content

Commit

Permalink
Add PHPStan (#171)
Browse files Browse the repository at this point in the history
Add PHPStan analysis
  • Loading branch information
antonkomarev authored Jun 21, 2020
1 parent a4a8317 commit c037dde
Show file tree
Hide file tree
Showing 30 changed files with 162 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 0
paths:
- src
- tests
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ before_script:
- if [[ $setup = 'lowest' ]]; then travis_retry composer update --prefer-dist --no-interaction --prefer-lowest --prefer-stable; fi

script:
- ./vendor/bin/phpstan analyse -c .phpstan.neon
- ./vendor/bin/phpunit -c phpunit.xml.dist --verbose
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"mockery/mockery": "^1.0",
"orchestra/database": "~3.7.0|~3.8.0|^4.0|^5.0",
"orchestra/testbench": "~3.7.0|~3.8.0|^4.0|^5.0",
"phpstan/phpstan": "^0.12.29",
"phpunit/phpunit": "^7.5|^8.0|^9.0"
},
"autoload": {
Expand Down
3 changes: 3 additions & 0 deletions src/Console/Commands/ReactionTypeAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public function handle(): int
return 0;
}

/**
* @return array[]
*/
protected function getOptions(): array
{
return [
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Commands/Recount.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class Recount extends Command
/**
* Get the console command options.
*
* @return array
* @return array[]
*/
protected function getOptions(
): array {
Expand Down
3 changes: 3 additions & 0 deletions src/Console/Commands/RegisterReactants.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class RegisterReactants extends Command
*/
protected $description = 'Register Reactable models as Reactants';

/**
* @return array[]
*/
protected function getOptions(): array
{
return [
Expand Down
3 changes: 3 additions & 0 deletions src/Console/Commands/RegisterReacters.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ final class RegisterReacters extends Command
*/
protected $description = 'Register Reacterable models as Reacters';

/**
* @return array[]
*/
protected function getOptions(): array
{
return [
Expand Down
12 changes: 12 additions & 0 deletions src/Console/Commands/SetupReactable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ final class SetupReactable extends Command
*/
protected $description = 'Set up reactable model';

/**
* @var Filesystem
*/
private $files;

/**
* @var MigrationCreator
*/
private $creator;

/**
* @var Composer
*/
private $composer;

public function __construct(Filesystem $files, MigrationCreator $creator, Composer $composer)
Expand Down Expand Up @@ -133,6 +142,9 @@ public function handle(): int
return 0;
}

/**
* @return array[]
*/
protected function getOptions(): array
{
return [
Expand Down
12 changes: 12 additions & 0 deletions src/Console/Commands/SetupReacterable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,19 @@ final class SetupReacterable extends Command
*/
protected $description = 'Set up reacterable model';

/**
* @var Filesystem
*/
private $files;

/**
* @var MigrationCreator
*/
private $creator;

/**
* @var Composer
*/
private $composer;

public function __construct(Filesystem $files, MigrationCreator $creator, Composer $composer)
Expand Down Expand Up @@ -133,6 +142,9 @@ public function handle(): int
return 0;
}

/**
* @return array[]
*/
protected function getOptions(): array
{
return [
Expand Down
9 changes: 9 additions & 0 deletions src/Reactant/Facades/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,27 @@
final class Reactant implements
ReacterFacadeContract
{
/**
* @var ReactantContract
*/
private $reactant;

public function __construct(ReactantContract $reactant)
{
$this->reactant = $reactant;
}

/**
* @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[]
*/
public function getReactions(): iterable
{
return $this->reactant->getReactions();
}

/**
* @return iterable|\Cog\Contracts\Love\Reactant\ReactionCounter\Models\ReactionCounter[]
*/
public function getReactionCounters(): iterable
{
return $this->reactant->getReactionCounters();
Expand Down
2 changes: 1 addition & 1 deletion src/Reactant/Jobs/RebuildReactionAggregatesJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private function resetCountersValues(
}

/**
* @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
* @return \Cog\Laravel\Love\Reaction\Models\Reaction[]|\Illuminate\Database\Eloquent\Collection
*/
private function collectReactions(
): iterable {
Expand Down
3 changes: 3 additions & 0 deletions src/Reactant/Models/NullReactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
final class NullReactant implements
ReactantContract
{
/**
* @var ReactableContract
*/
private $reactable;

public function __construct(
Expand Down
6 changes: 6 additions & 0 deletions src/Reactant/Models/Reactant.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,16 @@ final class Reactant extends Model implements
{
protected $table = 'love_reactants';

/**
* @var string[]
*/
protected $fillable = [
'type',
];

/**
* @var string[]
*/
protected $casts = [
'id' => 'string',
];
Expand Down
6 changes: 6 additions & 0 deletions src/Reactant/ReactionCounter/Models/NullReactionCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,14 @@
final class NullReactionCounter implements
ReactionCounterContract
{
/**
* @var ReactantContract
*/
private $reactant;

/**
* @var ReactionTypeContract
*/
private $reactionType;

public function __construct(
Expand Down
9 changes: 9 additions & 0 deletions src/Reactant/ReactionCounter/Models/ReactionCounter.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,26 @@ final class ReactionCounter extends Model implements

protected $table = 'love_reactant_reaction_counters';

/**
* @var array<int|float>
*/
protected $attributes = [
'count' => self::COUNT_DEFAULT,
'weight' => self::WEIGHT_DEFAULT,
];

/**
* @var string[]
*/
protected $fillable = [
'reaction_type_id',
'count',
'weight',
];

/**
* @var string[]
*/
protected $casts = [
'count' => 'integer',
'weight' => 'float',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@

final class ReactionCounterService
{
/**
* @var ReactantContract
*/
private $reactant;

public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/Reactant/ReactionTotal/Models/NullReactionTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
final class NullReactionTotal implements
ReactionTotalContract
{
/**
* @var ReactantContract
*/
private $reactant;

public function __construct(
Expand Down
9 changes: 9 additions & 0 deletions src/Reactant/ReactionTotal/Models/ReactionTotal.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,25 @@ final class ReactionTotal extends Model implements

protected $table = 'love_reactant_reaction_totals';

/**
* @var array<int|float>
*/
protected $attributes = [
'count' => self::COUNT_DEFAULT,
'weight' => self::WEIGHT_DEFAULT,
];

/**
* @var string[]
*/
protected $fillable = [
'count',
'weight',
];

/**
* @var string[]
*/
protected $casts = [
'count' => 'integer',
'weight' => 'float',
Expand Down
3 changes: 3 additions & 0 deletions src/Reactant/ReactionTotal/Services/ReactionTotalService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

final class ReactionTotalService
{
/**
* @var ReactionTotalContract
*/
private $reactionTotal;

public function __construct(
Expand Down
6 changes: 6 additions & 0 deletions src/Reacter/Facades/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@
final class Reacter implements
ReacterFacadeContract
{
/**
* @var ReacterContract
*/
private $reacter;

public function __construct(ReacterContract $reacter)
{
$this->reacter = $reacter;
}

/**
* @return iterable|\Cog\Contracts\Love\Reaction\Models\Reaction[]
*/
public function getReactions(): iterable
{
return $this->reacter->getReactions();
Expand Down
3 changes: 3 additions & 0 deletions src/Reacter/Models/NullReacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
final class NullReacter implements
ReacterContract
{
/**
* @var ReacterableContract
*/
private $reacterable;

public function __construct(
Expand Down
8 changes: 7 additions & 1 deletion src/Reacter/Models/Reacter.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ final class Reacter extends Model implements
{
protected $table = 'love_reacters';

/**
* @var string[]
*/
protected $fillable = [
'type',
];

/**
* @var string[]
*/
protected $casts = [
'id' => 'string',
];
Expand Down Expand Up @@ -176,7 +182,7 @@ private function createReaction(
/**
* @param \Cog\Contracts\Love\Reactant\Models\Reactant $reactant
* @param \Cog\Contracts\Love\ReactionType\Models\ReactionType $reactionType
* @return null|\Cog\Contracts\Love\Reaction\Models\Reaction|\Illuminate\Database\Eloquent\Model
* @return \Cog\Contracts\Love\Reaction\Models\Reaction|\Illuminate\Database\Eloquent\Model|null
*/
private function findReaction(
ReactantContract $reactant,
Expand Down
3 changes: 3 additions & 0 deletions src/Reaction/Events/ReactionHasBeenAdded.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

final class ReactionHasBeenAdded
{
/**
* @var ReactionContract
*/
private $reaction;

public function __construct(
Expand Down
3 changes: 3 additions & 0 deletions src/Reaction/Events/ReactionHasBeenRemoved.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

final class ReactionHasBeenRemoved
{
/**
* @var ReactionContract
*/
private $reaction;

public function __construct(
Expand Down
9 changes: 9 additions & 0 deletions src/Reaction/Models/Reaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,25 @@ final class Reaction extends Model implements

protected $table = 'love_reactions';

/**
* @var float[]
*/
protected $attributes = [
'rate' => self::RATE_DEFAULT,
];

/**
* @var string[]
*/
protected $fillable = [
'reactant_id',
'reaction_type_id',
'rate',
];

/**
* @var string[]
*/
protected $casts = [
'id' => 'string',
'rate' => 'float',
Expand Down
3 changes: 3 additions & 0 deletions src/Reaction/Observers/ReactionObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@

final class ReactionObserver
{
/**
* @var DispatcherContract
*/
private $eventDispatcher;

public function __construct(
Expand Down
Loading

0 comments on commit c037dde

Please sign in to comment.