Skip to content

Commit

Permalink
Added CustomFieldBehavior to make phpstan happy
Browse files Browse the repository at this point in the history
  • Loading branch information
janhenckens committed Feb 16, 2024
1 parent 2348440 commit dc8ace9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
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: 3 additions & 0 deletions lib/craft/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<?php

define('CRAFT_BASE_PATH', __DIR__);
7 changes: 5 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
includes:
- vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 1
paths:
- src
- src
scanFiles:
- lib/craft/behaviors/CustomFieldBehavior.php
bootstrapFiles:
- lib/craft/bootstrap.php
3 changes: 2 additions & 1 deletion src/Scout.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ function(ElementEvent $event) {
$element = $event->element;
$baseElement = ElementHelper::rootElementIfCanonical($element);
if ($baseElement) {
/** @phpstan-var UrlManager $urlManager */
if (!$baseElement->hasMethod('searchable') || !$baseElement->shouldBeSearchable()) {
return;
}
Expand All @@ -171,7 +172,7 @@ function(ElementEvent $event) {
->push(
new IndexElement([
'id' => $baseElement->id,
'siteId' => $baseElement->site ? $baseElement->site->id : null
'siteId' => $baseElement->site ? $baseElement->site->id : null,
])
);
} else {
Expand Down

0 comments on commit dc8ace9

Please sign in to comment.