Skip to content

Commit

Permalink
Get PHPStan working when Craft isn't installed yet
Browse files Browse the repository at this point in the history
Now only requires `codecept build`
  • Loading branch information
brandonkelly committed Mar 31, 2022
1 parent bd8edb3 commit cd0f3b7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/ecs.php export-ignore
/gulpfile.js export-ignore
/lerna.json export-ignore
/lib/craft/behaviors/CustomFieldBehavior.php export-ignore
/package-lock.json export-ignore
/package.json export-ignore
/packages/ export-ignore
Expand Down
33 changes: 33 additions & 0 deletions lib/craft/behaviors/CustomFieldBehavior.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* @link http://craftcms.com/
* @copyright Copyright (c) Pixel & Tonic, Inc.
* @license http://craftcms.com/license
*/

namespace craft\behaviors;

use yii\base\Behavior;

/**
* This file is never loaded at runtime. It’s only here for PHPStan’n sake.
*
* @internal
*/
class CustomFieldBehavior extends Behavior
{
/**
* @var bool Whether the behavior should provide methods based on the field handles.
*/
public bool $hasMethods = false;

/**
* @var bool Whether properties on the class should be settable directly.
*/
public bool $canSetProperties = true;

/**
* @var string[] List of supported field handles.
*/
public static $fieldHandles = [];
}
3 changes: 1 addition & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ parameters:
- tests/_data/*
- tests/_output/*
- tests/_support/_generated/
scanDirectories:
- tests/_craft/storage/runtime/compiled_classes/
scanFiles:
- lib/craft/behaviors/CustomFieldBehavior.php
- tests/_support/_generated/AcceptanceTesterActions.php
- tests/_support/_generated/FunctionalTesterActions.php
- tests/_support/_generated/GqlTesterActions.php
Expand Down
5 changes: 5 additions & 0 deletions src/Craft.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public static function autoload($className): void
*/
private static function _autoloadCustomFieldBehavior(): void
{
if (!isset(static::$app)) {
// Nothing we can do about it yet
return;
}

if (!static::$app->getIsInstalled()) {
// Just load an empty CustomFieldBehavior into memory
self::_generateCustomFieldBehavior([], null, false, true);
Expand Down

0 comments on commit cd0f3b7

Please sign in to comment.