bmitch/churn-php

View on GitHub
src/Process/Handler/BaseProcessHandler.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

declare(strict_types=1);

namespace Churn\Process\Handler;

use Churn\Process\ChangesCountInterface;
use Churn\Process\CyclomaticComplexityInterface;
use Churn\Process\ProcessInterface;
use Churn\Result\Result;

/**
 * @internal
 */
abstract class BaseProcessHandler implements ProcessHandler
{
    /**
     * @param ProcessInterface $process A successful process.
     * @param Result $result The result object to hydrate.
     */
    protected function saveResult(ProcessInterface $process, Result $result): Result
    {
        if ($process instanceof ChangesCountInterface) {
            $result->setCommits($process->countChanges());
        }

        if ($process instanceof CyclomaticComplexityInterface) {
            $result->setComplexity($process->getCyclomaticComplexity());
        }

        return $result;
    }
}