Syndesi/neo4j-sync-bundle

View on GitHub
src/Helper/CompareEqualHelper.php

Summary

Maintainability
A
30 mins
Test Coverage
C
70%
<?php

declare(strict_types=1);

namespace Syndesi\Neo4jSyncBundle\Helper;

use Syndesi\Neo4jSyncBundle\Contract\IsEqualToInterface;

class CompareEqualHelper
{
    public static function compare(?IsEqualToInterface $a, ?IsEqualToInterface $b): bool
    {
        if (null === $a && null === $b) {
            return true;
        }
        if (null === $a) {
            return false;
        }
        if (null === $b) {
            return false;
        }
        // a and b must be not null
        /** @psalm-suppress PossiblyNullArgument */
        if (get_class($a) !== get_class($b)) {
            return false;
        }

        return $a->isEqualTo($b);
    }
}