for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @copyright Copyright (c) Flipbox Digital Limited
* @license https://flipboxfactory.com/software/scorecard/license
* @link https://www.flipboxfactory.com/software/scorecard/
*/
namespace flipbox\craft\scorecard\metrics;
use craft\helpers\StringHelper;
use yii\base\BaseObject;
* @author Flipbox Factory <[email protected]>
* @since 1.0.0
abstract class AbstractMetric extends BaseObject implements MetricInterface
{
* @var float
public $weight = 1;
* @var string
public $version = '1.0.0';
private $score;
* @return float
abstract protected function calculateScore(): float;
* @inheritdoc
* @throws \ReflectionException
public static function displayName(): string
return preg_replace(
'/(?<!^)([A-Z])/',
' $0',
(new \ReflectionClass(static::class))
->getShortName()
);
}
public function getVersion(): string
return $this->version;
public function getWeight(): float
return $this->weight;
public function getScore(): float
if ($this->score === null) {
$this->score = $this->calculateScore();
return $this->score * $this->getWeight();
* @return $this
public function resetScore()
$this->score = null;
return $this;
* @param float|null $score
public function setScore(float $score = null)
$this->score = $score;
public function toConfig(): array
return [
'class' => static::class,
'weight' => $this->getWeight(),
'version' => $this->getVersion(),
'score' => $this->getScore()
];