Skip to content

Instantly share code, notes, and snippets.

@shadowhand
Created April 27, 2015 19:46
Show Gist options
  • Save shadowhand/915ff25729b038577475 to your computer and use it in GitHub Desktop.
Save shadowhand/915ff25729b038577475 to your computer and use it in GitHub Desktop.
Check if a class implements all methods of an interface
<?php
# Created for https://github.com/facebook/hhvm/issues/5170
require 'vendor/autoload.php';
$i = new ReflectionClass('League\OAuth2\Client\Provider\ProviderInterface');
$c = new ReflectionClass('League\OAuth2\Client\Provider\AbstractProvider');
$r = [];
$h = [];
foreach ($i->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
$r[] = $method->getName();
}
foreach ($c->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if ($method->getDeclaringClass() == $c) {
$h[] = $method->getName();
}
}
$missing = array_diff($r, $h);
if (empty($missing)) {
printf("OKAY: %s implements all methods of %s\n",
$c->getName(),
$i->getName()
);
} else {
printf("ERROR: %s is missing some methods of %s:\n- %s\n",
$c->getName(),
$i->getName(),
implode("\n- ", $missing)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment