id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
41,900 | eloquent/phony | src/Verification/Cardinality.php | Cardinality.matches | public function matches($count, int $maximumCount): bool
{
$count = intval($count);
$result = true;
if ($count < $this->minimum) {
$result = false;
}
if ($this->maximum >= 0 && $count > $this->maximum) {
$result = false;
}
if ($this->isAlways && $count < $maximumCount) {
$result = false;
}
return $result;
} | php | public function matches($count, int $maximumCount): bool
{
$count = intval($count);
$result = true;
if ($count < $this->minimum) {
$result = false;
}
if ($this->maximum >= 0 && $count > $this->maximum) {
$result = false;
}
if ($this->isAlways && $count < $maximumCount) {
$result = false;
}
return $result;
} | [
"public",
"function",
"matches",
"(",
"$",
"count",
",",
"int",
"$",
"maximumCount",
")",
":",
"bool",
"{",
"$",
"count",
"=",
"intval",
"(",
"$",
"count",
")",
";",
"$",
"result",
"=",
"true",
";",
"if",
"(",
"$",
"count",
"<",
"$",
"this",
"->"... | Returns true if the supplied count matches this cardinality.
@param int|bool $count The count or result to check.
@param int $maximumCount The maximum possible count.
@return bool True if the supplied count matches this cardinality. | [
"Returns",
"true",
"if",
"the",
"supplied",
"count",
"matches",
"this",
"cardinality",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/Cardinality.php#L113-L131 |
41,901 | eloquent/phony | src/Verification/Cardinality.php | Cardinality.assertSingular | public function assertSingular(): self
{
if ($this->minimum > 1 || $this->maximum > 1 || $this->isAlways) {
throw new InvalidSingularCardinalityException($this);
}
return $this;
} | php | public function assertSingular(): self
{
if ($this->minimum > 1 || $this->maximum > 1 || $this->isAlways) {
throw new InvalidSingularCardinalityException($this);
}
return $this;
} | [
"public",
"function",
"assertSingular",
"(",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"minimum",
">",
"1",
"||",
"$",
"this",
"->",
"maximum",
">",
"1",
"||",
"$",
"this",
"->",
"isAlways",
")",
"{",
"throw",
"new",
"InvalidSingularCardinal... | Asserts that this cardinality is suitable for events that can only happen
once or not at all.
@return $this This cardinality.
@throws InvalidCardinalityException If the cardinality is invalid. | [
"Asserts",
"that",
"this",
"cardinality",
"is",
"suitable",
"for",
"events",
"that",
"can",
"only",
"happen",
"once",
"or",
"not",
"at",
"all",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/Cardinality.php#L140-L147 |
41,902 | chadicus/slim-oauth2-routes | src/UserIdProvider.php | UserIdProvider.getUserId | public function getUserId(ServerRequestInterface $request, array $arguments = [])
{
$queryParams = $request->getQueryParams();
return array_key_exists('user_id', $queryParams) ? $queryParams['user_id'] : null;
} | php | public function getUserId(ServerRequestInterface $request, array $arguments = [])
{
$queryParams = $request->getQueryParams();
return array_key_exists('user_id', $queryParams) ? $queryParams['user_id'] : null;
} | [
"public",
"function",
"getUserId",
"(",
"ServerRequestInterface",
"$",
"request",
",",
"array",
"$",
"arguments",
"=",
"[",
"]",
")",
"{",
"$",
"queryParams",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
";",
"return",
"array_key_exists",
"(",
"'us... | Extracts a user_id from the given HTTP request query params.
@param ServerRequestInterface $request The incoming HTTP request.
@param array $arguments Any route parameters associated with the request.
@return string|null The user id if it exists, otherwise null | [
"Extracts",
"a",
"user_id",
"from",
"the",
"given",
"HTTP",
"request",
"query",
"params",
"."
] | d69d4e32102651de044860b38e686c9759150d7f | https://github.com/chadicus/slim-oauth2-routes/blob/d69d4e32102651de044860b38e686c9759150d7f/src/UserIdProvider.php#L20-L24 |
41,903 | eloquent/phony | src/Mock/MockFactory.php | MockFactory.createMockClass | public function createMockClass(
MockDefinition $definition,
bool $createNew = false
): ReflectionClass {
$signature = $definition->signature();
if (!$createNew) {
foreach ($this->definitions as $tuple) {
if ($signature === $tuple[0]) {
return $tuple[1];
}
}
}
$className = $this->generator->generateClassName($definition);
if (class_exists($className, false)) {
throw new ClassExistsException($className);
}
$source = $this->generator->generate($definition, $className);
$reporting = error_reporting(E_ERROR | E_COMPILE_ERROR);
try {
eval($source);
} catch (ParseError $e) {
throw new MockGenerationFailedException(
$className,
$definition,
$source,
error_get_last(),
$e
);
} finally {
error_reporting($reporting);
}
if (!class_exists($className, false)) {
// @codeCoverageIgnoreStart
throw new MockGenerationFailedException(
$className,
$definition,
$source,
error_get_last()
);
// @codeCoverageIgnoreEnd
}
$class = new ReflectionClass($className);
$customMethods = [];
foreach ($definition->customStaticMethods() as $methodName => $method) {
$customMethods[strtolower($methodName)] = $method[0];
}
foreach ($definition->customMethods() as $methodName => $method) {
$customMethods[strtolower($methodName)] = $method[0];
}
$customMethodsProperty = $class->getProperty('_customMethods');
$customMethodsProperty->setAccessible(true);
$customMethodsProperty->setValue(null, $customMethods);
$this->handleFactory->staticHandle($class);
$this->definitions[] = [$signature, $class];
return $class;
} | php | public function createMockClass(
MockDefinition $definition,
bool $createNew = false
): ReflectionClass {
$signature = $definition->signature();
if (!$createNew) {
foreach ($this->definitions as $tuple) {
if ($signature === $tuple[0]) {
return $tuple[1];
}
}
}
$className = $this->generator->generateClassName($definition);
if (class_exists($className, false)) {
throw new ClassExistsException($className);
}
$source = $this->generator->generate($definition, $className);
$reporting = error_reporting(E_ERROR | E_COMPILE_ERROR);
try {
eval($source);
} catch (ParseError $e) {
throw new MockGenerationFailedException(
$className,
$definition,
$source,
error_get_last(),
$e
);
} finally {
error_reporting($reporting);
}
if (!class_exists($className, false)) {
// @codeCoverageIgnoreStart
throw new MockGenerationFailedException(
$className,
$definition,
$source,
error_get_last()
);
// @codeCoverageIgnoreEnd
}
$class = new ReflectionClass($className);
$customMethods = [];
foreach ($definition->customStaticMethods() as $methodName => $method) {
$customMethods[strtolower($methodName)] = $method[0];
}
foreach ($definition->customMethods() as $methodName => $method) {
$customMethods[strtolower($methodName)] = $method[0];
}
$customMethodsProperty = $class->getProperty('_customMethods');
$customMethodsProperty->setAccessible(true);
$customMethodsProperty->setValue(null, $customMethods);
$this->handleFactory->staticHandle($class);
$this->definitions[] = [$signature, $class];
return $class;
} | [
"public",
"function",
"createMockClass",
"(",
"MockDefinition",
"$",
"definition",
",",
"bool",
"$",
"createNew",
"=",
"false",
")",
":",
"ReflectionClass",
"{",
"$",
"signature",
"=",
"$",
"definition",
"->",
"signature",
"(",
")",
";",
"if",
"(",
"!",
"$... | Create the mock class for the supplied definition.
@param MockDefinition $definition The definition.
@param bool $createNew True if a new class should be created even when a compatible one exists.
@return ReflectionClass The class.
@throws MockException If the mock generation fails. | [
"Create",
"the",
"mock",
"class",
"for",
"the",
"supplied",
"definition",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockFactory.php#L67-L134 |
41,904 | eloquent/phony | src/Mock/MockFactory.php | MockFactory.createFullMock | public function createFullMock(ReflectionClass $class): Mock
{
$mock = $class->newInstanceWithoutConstructor();
$this->handleFactory
->instanceHandle($mock, strval($this->labelSequencer->next()));
return $mock;
} | php | public function createFullMock(ReflectionClass $class): Mock
{
$mock = $class->newInstanceWithoutConstructor();
$this->handleFactory
->instanceHandle($mock, strval($this->labelSequencer->next()));
return $mock;
} | [
"public",
"function",
"createFullMock",
"(",
"ReflectionClass",
"$",
"class",
")",
":",
"Mock",
"{",
"$",
"mock",
"=",
"$",
"class",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"$",
"this",
"->",
"handleFactory",
"->",
"instanceHandle",
"(",
"$",
"... | Create a new full mock instance for the supplied class.
@param ReflectionClass $class The class.
@return Mock The newly created mock.
@throws MockException If the mock generation fails. | [
"Create",
"a",
"new",
"full",
"mock",
"instance",
"for",
"the",
"supplied",
"class",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockFactory.php#L144-L151 |
41,905 | eloquent/phony | src/Mock/MockFactory.php | MockFactory.createPartialMock | public function createPartialMock(
ReflectionClass $class,
$arguments = []
): Mock {
$mock = $class->newInstanceWithoutConstructor();
$handle = $this->handleFactory
->instanceHandle($mock, strval($this->labelSequencer->next()));
$handle->partial();
if (null !== $arguments) {
$handle->constructWith($arguments);
}
return $mock;
} | php | public function createPartialMock(
ReflectionClass $class,
$arguments = []
): Mock {
$mock = $class->newInstanceWithoutConstructor();
$handle = $this->handleFactory
->instanceHandle($mock, strval($this->labelSequencer->next()));
$handle->partial();
if (null !== $arguments) {
$handle->constructWith($arguments);
}
return $mock;
} | [
"public",
"function",
"createPartialMock",
"(",
"ReflectionClass",
"$",
"class",
",",
"$",
"arguments",
"=",
"[",
"]",
")",
":",
"Mock",
"{",
"$",
"mock",
"=",
"$",
"class",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"$",
"handle",
"=",
"$",
"... | Create a new partial mock instance for the supplied definition.
@param ReflectionClass $class The class.
@param Arguments|array|null $arguments The constructor arguments, or null to bypass the constructor.
@return Mock The newly created mock.
@throws MockException If the mock generation fails. | [
"Create",
"a",
"new",
"partial",
"mock",
"instance",
"for",
"the",
"supplied",
"definition",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/MockFactory.php#L162-L176 |
41,906 | eloquent/phony | src/Stub/EmptyValueFactory.php | EmptyValueFactory.fromType | public function fromType(ReflectionType $type)
{
if ($type->allowsNull()) {
return null;
}
$typeName = strval($type);
switch (strtolower($typeName)) {
case 'bool':
return false;
case 'int':
return 0;
case 'float':
return .0;
case 'string':
return '';
case 'array':
case 'iterable':
return [];
case 'object':
// @codeCoverageIgnoreStart
if (!$this->isObjectTypeSupported) {
break;
}
// @codeCoverageIgnoreEnd
// no break
case 'stdclass':
return (object) [];
case 'callable':
return $this->stubVerifierFactory->create();
case 'closure':
return function () {};
case 'generator':
$fn = function () { return; yield; };
return $fn();
case 'void':
return null;
}
return $this->mockBuilderFactory->create($typeName)->full();
} | php | public function fromType(ReflectionType $type)
{
if ($type->allowsNull()) {
return null;
}
$typeName = strval($type);
switch (strtolower($typeName)) {
case 'bool':
return false;
case 'int':
return 0;
case 'float':
return .0;
case 'string':
return '';
case 'array':
case 'iterable':
return [];
case 'object':
// @codeCoverageIgnoreStart
if (!$this->isObjectTypeSupported) {
break;
}
// @codeCoverageIgnoreEnd
// no break
case 'stdclass':
return (object) [];
case 'callable':
return $this->stubVerifierFactory->create();
case 'closure':
return function () {};
case 'generator':
$fn = function () { return; yield; };
return $fn();
case 'void':
return null;
}
return $this->mockBuilderFactory->create($typeName)->full();
} | [
"public",
"function",
"fromType",
"(",
"ReflectionType",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"->",
"allowsNull",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"typeName",
"=",
"strval",
"(",
"$",
"type",
")",
";",
"switch",
"(",
"... | Create a value of the supplied type.
@param ReflectionType $type The type.
@return mixed A value of the supplied type. | [
"Create",
"a",
"value",
"of",
"the",
"supplied",
"type",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/EmptyValueFactory.php#L71-L124 |
41,907 | eloquent/phony | src/Verification/GeneratorVerifier.php | GeneratorVerifier.checkReceived | public function checkReceived($value = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$checkValue = false;
} else {
$checkValue = true;
$value = $this->matcherFactory->adapt($value);
}
$isCall = $this->subject instanceof Call;
$matchingEvents = [];
$matchCount = 0;
$eventCount = 0;
foreach ($this->calls as $call) {
$isMatchingCall = false;
foreach ($call->iterableEvents() as $event) {
if ($event instanceof ReceivedEvent) {
++$eventCount;
if (!$checkValue || $value->matches($event->value())) {
$matchingEvents[] = $event;
$isMatchingCall = true;
if ($isCall) {
++$matchCount;
}
}
}
}
if (!$isCall && $isMatchingCall) {
++$matchCount;
}
}
if ($isCall) {
$totalCount = $eventCount;
} else {
$totalCount = $this->callCount;
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkReceived($value = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$checkValue = false;
} else {
$checkValue = true;
$value = $this->matcherFactory->adapt($value);
}
$isCall = $this->subject instanceof Call;
$matchingEvents = [];
$matchCount = 0;
$eventCount = 0;
foreach ($this->calls as $call) {
$isMatchingCall = false;
foreach ($call->iterableEvents() as $event) {
if ($event instanceof ReceivedEvent) {
++$eventCount;
if (!$checkValue || $value->matches($event->value())) {
$matchingEvents[] = $event;
$isMatchingCall = true;
if ($isCall) {
++$matchCount;
}
}
}
}
if (!$isCall && $isMatchingCall) {
++$matchCount;
}
}
if ($isCall) {
$totalCount = $eventCount;
} else {
$totalCount = $this->callCount;
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkReceived",
"(",
"$",
"value",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"argumentCount",
"=",
"func_num_args",
"(",
")",
";",
"if",
... | Checks if the subject received the supplied value.
When called with no arguments, this method simply checks that the subject
received any value.
@param mixed $value The value.
@return EventCollection|null The result. | [
"Checks",
"if",
"the",
"subject",
"received",
"the",
"supplied",
"value",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L66-L117 |
41,908 | eloquent/phony | src/Verification/GeneratorVerifier.php | GeneratorVerifier.received | public function received($value = null): ?EventCollection
{
$cardinality = $this->cardinality;
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$arguments = [];
} else {
$value = $this->matcherFactory->adapt($value);
$arguments = [$value];
}
if ($result = $this->checkReceived(...$arguments)) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer
->renderGeneratorReceived($this->subject, $cardinality, $value)
);
} | php | public function received($value = null): ?EventCollection
{
$cardinality = $this->cardinality;
$argumentCount = func_num_args();
if (0 === $argumentCount) {
$arguments = [];
} else {
$value = $this->matcherFactory->adapt($value);
$arguments = [$value];
}
if ($result = $this->checkReceived(...$arguments)) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer
->renderGeneratorReceived($this->subject, $cardinality, $value)
);
} | [
"public",
"function",
"received",
"(",
"$",
"value",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"$",
"argumentCount",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"0",
"===",
"... | Throws an exception unless the subject received the supplied value.
When called with no arguments, this method simply checks that the subject
received any value.
@param mixed $value The value.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"the",
"subject",
"received",
"the",
"supplied",
"value",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L130-L150 |
41,909 | eloquent/phony | src/Verification/GeneratorVerifier.php | GeneratorVerifier.receivedException | public function receivedException($type = null): ?EventCollection
{
$cardinality = $this->cardinality;
if ($type instanceof InstanceHandle) {
$type = $type->get();
}
if ($type instanceof Throwable) {
$type = $this->matcherFactory->equalTo($type, true);
} elseif ($this->matcherFactory->isMatcher($type)) {
$type = $this->matcherFactory->adapt($type);
}
if ($result = $this->checkReceivedException($type)) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderGeneratorReceivedException(
$this->subject,
$cardinality,
$type
)
);
} | php | public function receivedException($type = null): ?EventCollection
{
$cardinality = $this->cardinality;
if ($type instanceof InstanceHandle) {
$type = $type->get();
}
if ($type instanceof Throwable) {
$type = $this->matcherFactory->equalTo($type, true);
} elseif ($this->matcherFactory->isMatcher($type)) {
$type = $this->matcherFactory->adapt($type);
}
if ($result = $this->checkReceivedException($type)) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderGeneratorReceivedException(
$this->subject,
$cardinality,
$type
)
);
} | [
"public",
"function",
"receivedException",
"(",
"$",
"type",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"if",
"(",
"$",
"type",
"instanceof",
"InstanceHandle",
")",
"{",
"$",
"type",
... | Throws an exception unless the subject received an exception of the
supplied type.
@param Matcher|Throwable|string|null $type An exception to match, the type of exception, or null for any exception.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws InvalidArgumentException If the type is invalid.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"the",
"subject",
"received",
"an",
"exception",
"of",
"the",
"supplied",
"type",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L289-L314 |
41,910 | eloquent/phony | src/Verification/GeneratorVerifier.php | GeneratorVerifier.checkReturned | public function checkReturned($value = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
if (0 === func_num_args()) {
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception) = $call->generatorResponse();
if (!$exception) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
} else {
$value = $this->matcherFactory->adapt($value);
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception, $returnValue) = $call->generatorResponse();
if (!$exception && $value->matches($returnValue)) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkReturned($value = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
if (0 === func_num_args()) {
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception) = $call->generatorResponse();
if (!$exception) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
} else {
$value = $this->matcherFactory->adapt($value);
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception, $returnValue) = $call->generatorResponse();
if (!$exception && $value->matches($returnValue)) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkReturned",
"(",
"$",
"value",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"subject",
"instanceof",
"Call",
")... | Checks if the subject returned the supplied value from a generator.
@param mixed $value The value.
@return EventCollection|null The result. | [
"Checks",
"if",
"the",
"subject",
"returned",
"the",
"supplied",
"value",
"from",
"a",
"generator",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L323-L369 |
41,911 | eloquent/phony | src/Verification/GeneratorVerifier.php | GeneratorVerifier.checkThrew | public function checkThrew($type = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
$isTypeSupported = false;
if (!$type) {
$isTypeSupported = true;
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception) = $call->generatorResponse();
if ($exception) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
} elseif (is_string($type)) {
$isTypeSupported = true;
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception) = $call->generatorResponse();
if ($exception && is_a($exception, $type)) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
} elseif (is_object($type)) {
if ($type instanceof InstanceHandle) {
$type = $type->get();
}
if ($type instanceof Throwable) {
$isTypeSupported = true;
$type = $this->matcherFactory->equalTo($type, true);
} elseif ($this->matcherFactory->isMatcher($type)) {
$isTypeSupported = true;
$type = $this->matcherFactory->adapt($type);
}
if ($isTypeSupported) {
foreach ($this->calls as $call) {
if (
!$call->isGenerator() ||
!$endEvent = $call->endEvent()
) {
continue;
}
list($exception) = $call->generatorResponse();
if ($exception && $type->matches($exception)) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
}
}
if (!$isTypeSupported) {
throw new InvalidArgumentException(
sprintf(
'Unable to match exceptions against %s.',
$this->assertionRenderer->renderValue($type)
)
);
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkThrew($type = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
if ($this->subject instanceof Call) {
$cardinality->assertSingular();
}
$matchingEvents = [];
$matchCount = 0;
$isTypeSupported = false;
if (!$type) {
$isTypeSupported = true;
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception) = $call->generatorResponse();
if ($exception) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
} elseif (is_string($type)) {
$isTypeSupported = true;
foreach ($this->calls as $call) {
if (!$call->isGenerator() || !$endEvent = $call->endEvent()) {
continue;
}
list($exception) = $call->generatorResponse();
if ($exception && is_a($exception, $type)) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
} elseif (is_object($type)) {
if ($type instanceof InstanceHandle) {
$type = $type->get();
}
if ($type instanceof Throwable) {
$isTypeSupported = true;
$type = $this->matcherFactory->equalTo($type, true);
} elseif ($this->matcherFactory->isMatcher($type)) {
$isTypeSupported = true;
$type = $this->matcherFactory->adapt($type);
}
if ($isTypeSupported) {
foreach ($this->calls as $call) {
if (
!$call->isGenerator() ||
!$endEvent = $call->endEvent()
) {
continue;
}
list($exception) = $call->generatorResponse();
if ($exception && $type->matches($exception)) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
}
}
if (!$isTypeSupported) {
throw new InvalidArgumentException(
sprintf(
'Unable to match exceptions against %s.',
$this->assertionRenderer->renderValue($type)
)
);
}
if ($cardinality->matches($matchCount, $this->callCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkThrew",
"(",
"$",
"type",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"subject",
"instanceof",
"Call",
")",
... | Checks if an exception of the supplied type was thrown from a generator.
@param Matcher|Throwable|string|null $type An exception to match, the type of exception, or null for any exception.
@return EventCollection|null The result.
@throws InvalidArgumentException If the type is invalid. | [
"Checks",
"if",
"an",
"exception",
"of",
"the",
"supplied",
"type",
"was",
"thrown",
"from",
"a",
"generator",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifier.php#L410-L498 |
41,912 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.like | public function like(...$types): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$final = [];
foreach ($types as $type) {
if (is_array($type)) {
if (!empty($type)) {
if (array_values($type) === $type) {
$final = array_merge($final, $type);
} else {
$final[] = $type;
}
}
} else {
$final[] = $type;
}
}
$toAdd = [];
if (!$this->parentClassName) {
$parentClassNames = [];
} else {
$parentClassNames = [$this->parentClassName];
}
$parentClassName = '';
$definitions = [];
foreach ($final as $type) {
if (is_string($type)) {
try {
$type = new ReflectionClass($type);
} catch (ReflectionException $e) {
throw new InvalidTypeException($type, $e);
}
} elseif (is_array($type)) {
foreach ($type as $name => $value) {
if (!is_string($name)) {
throw new InvalidDefinitionException($name, $value);
}
}
$definitions[] = $type;
continue;
} else {
throw new InvalidTypeException($type);
}
if ($type->isAnonymous()) {
throw new AnonymousClassException();
}
$isTrait = $type->isTrait();
if (!$isTrait && $type->isFinal()) {
throw new FinalClassException($type->getName());
}
if (!$isTrait && !$type->isInterface()) {
$parentClassNames[] = $parentClassName = $type->getName();
}
$toAdd[] = $type;
}
$parentClassNames = array_unique($parentClassNames);
$parentClassCount = count($parentClassNames);
if ($parentClassCount > 1) {
throw new MultipleInheritanceException($parentClassNames);
}
foreach ($toAdd as $type) {
$name = strtolower($type->getName());
if (!isset($this->types[$name])) {
$this->types[$name] = $type;
}
}
if ($parentClassCount > 0) {
$this->parentClassName = $parentClassName;
}
foreach ($definitions as $definition) {
$this->define($definition);
}
return $this;
} | php | public function like(...$types): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$final = [];
foreach ($types as $type) {
if (is_array($type)) {
if (!empty($type)) {
if (array_values($type) === $type) {
$final = array_merge($final, $type);
} else {
$final[] = $type;
}
}
} else {
$final[] = $type;
}
}
$toAdd = [];
if (!$this->parentClassName) {
$parentClassNames = [];
} else {
$parentClassNames = [$this->parentClassName];
}
$parentClassName = '';
$definitions = [];
foreach ($final as $type) {
if (is_string($type)) {
try {
$type = new ReflectionClass($type);
} catch (ReflectionException $e) {
throw new InvalidTypeException($type, $e);
}
} elseif (is_array($type)) {
foreach ($type as $name => $value) {
if (!is_string($name)) {
throw new InvalidDefinitionException($name, $value);
}
}
$definitions[] = $type;
continue;
} else {
throw new InvalidTypeException($type);
}
if ($type->isAnonymous()) {
throw new AnonymousClassException();
}
$isTrait = $type->isTrait();
if (!$isTrait && $type->isFinal()) {
throw new FinalClassException($type->getName());
}
if (!$isTrait && !$type->isInterface()) {
$parentClassNames[] = $parentClassName = $type->getName();
}
$toAdd[] = $type;
}
$parentClassNames = array_unique($parentClassNames);
$parentClassCount = count($parentClassNames);
if ($parentClassCount > 1) {
throw new MultipleInheritanceException($parentClassNames);
}
foreach ($toAdd as $type) {
$name = strtolower($type->getName());
if (!isset($this->types[$name])) {
$this->types[$name] = $type;
}
}
if ($parentClassCount > 0) {
$this->parentClassName = $parentClassName;
}
foreach ($definitions as $definition) {
$this->define($definition);
}
return $this;
} | [
"public",
"function",
"like",
"(",
"...",
"$",
"types",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}",
"$",
"final",
"=",
"[",
"]",
";",
"foreach",
"(",
"$... | Add classes, interfaces, or traits.
Each value in `$types` can be either a class name, or an ad hoc mock
definition. If only a single type is being mocked, the class name or
definition can be passed without being wrapped in an array.
@param mixed ...$types Types to add.
@return $this This builder.
@throws MockException If invalid input is supplied, or this builder is already finalized. | [
"Add",
"classes",
"interfaces",
"or",
"traits",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L137-L232 |
41,913 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.addMethod | public function addMethod(string $name, callable $callback = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
if (!$callback) {
$callback = $this->emptyCallback;
}
$this->customMethods[$name] = [
$callback,
$this->invocableInspector->callbackReflector($callback),
];
return $this;
} | php | public function addMethod(string $name, callable $callback = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
if (!$callback) {
$callback = $this->emptyCallback;
}
$this->customMethods[$name] = [
$callback,
$this->invocableInspector->callbackReflector($callback),
];
return $this;
} | [
"public",
"function",
"addMethod",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}",
"i... | Add a custom method.
@param string $name The name.
@param callable|null $callback The callback.
@return $this This builder.
@throws MockException If this builder is already finalized. | [
"Add",
"a",
"custom",
"method",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L243-L258 |
41,914 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.addProperty | public function addProperty(string $name, $value = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$this->customProperties[$name] = $value;
return $this;
} | php | public function addProperty(string $name, $value = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$this->customProperties[$name] = $value;
return $this;
} | [
"public",
"function",
"addProperty",
"(",
"string",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}",
"$",
"this",
... | Add a custom property.
@param string $name The name.
@param mixed $value The value.
@return $this This builder.
@throws MockException If this builder is already finalized. | [
"Add",
"a",
"custom",
"property",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L269-L278 |
41,915 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.addStaticMethod | public function addStaticMethod(
string $name,
callable $callback = null
): self {
if ($this->isFinalized) {
throw new FinalizedMockException();
}
if (!$callback) {
$callback = $this->emptyCallback;
}
$this->customStaticMethods[$name] = [
$callback,
$this->invocableInspector->callbackReflector($callback),
];
return $this;
} | php | public function addStaticMethod(
string $name,
callable $callback = null
): self {
if ($this->isFinalized) {
throw new FinalizedMockException();
}
if (!$callback) {
$callback = $this->emptyCallback;
}
$this->customStaticMethods[$name] = [
$callback,
$this->invocableInspector->callbackReflector($callback),
];
return $this;
} | [
"public",
"function",
"addStaticMethod",
"(",
"string",
"$",
"name",
",",
"callable",
"$",
"callback",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}"... | Add a custom static method.
@param string $name The name.
@param callable|null $callback The callback.
@return $this This builder.
@throws MockException If this builder is already finalized. | [
"Add",
"a",
"custom",
"static",
"method",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L289-L306 |
41,916 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.addStaticProperty | public function addStaticProperty(string $name, $value = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$this->customStaticProperties[$name] = $value;
return $this;
} | php | public function addStaticProperty(string $name, $value = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$this->customStaticProperties[$name] = $value;
return $this;
} | [
"public",
"function",
"addStaticProperty",
"(",
"string",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}",
"$",
"thi... | Add a custom static property.
@param string $name The name.
@param mixed $value The value.
@return $this This builder.
@throws MockException If this builder is already finalized. | [
"Add",
"a",
"custom",
"static",
"property",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L317-L326 |
41,917 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.addConstant | public function addConstant(string $name, $value = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$this->customConstants[$name] = $value;
return $this;
} | php | public function addConstant(string $name, $value = null): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
$this->customConstants[$name] = $value;
return $this;
} | [
"public",
"function",
"addConstant",
"(",
"string",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}",
"$",
"this",
... | Add a custom class constant.
@param string $name The name.
@param mixed $value The value.
@return $this This builder.
@throws MockException If this builder is already finalized. | [
"Add",
"a",
"custom",
"class",
"constant",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L337-L346 |
41,918 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.named | public function named(string $className): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
if ('' !== $className) {
if (
!preg_match('/^' . static::SYMBOL_PATTERN . '$/S', $className)
) {
throw new InvalidClassNameException($className);
}
}
$this->className = $className;
return $this;
} | php | public function named(string $className): self
{
if ($this->isFinalized) {
throw new FinalizedMockException();
}
if ('' !== $className) {
if (
!preg_match('/^' . static::SYMBOL_PATTERN . '$/S', $className)
) {
throw new InvalidClassNameException($className);
}
}
$this->className = $className;
return $this;
} | [
"public",
"function",
"named",
"(",
"string",
"$",
"className",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"throw",
"new",
"FinalizedMockException",
"(",
")",
";",
"}",
"if",
"(",
"''",
"!==",
"$",
"className",
")",
... | Set the class name.
@param string $className The class name, or empty string to use a generated name.
@return $this This builder.
@throws MockException If this builder is already finalized. | [
"Set",
"the",
"class",
"name",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L356-L373 |
41,919 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.finalize | public function finalize(): self
{
if (!$this->isFinalized) {
$this->normalizeDefinition();
$this->isFinalized = true;
$this->definition = new MockDefinition(
$this->types,
$this->customMethods,
$this->customProperties,
$this->customStaticMethods,
$this->customStaticProperties,
$this->customConstants,
$this->className
);
}
return $this;
} | php | public function finalize(): self
{
if (!$this->isFinalized) {
$this->normalizeDefinition();
$this->isFinalized = true;
$this->definition = new MockDefinition(
$this->types,
$this->customMethods,
$this->customProperties,
$this->customStaticMethods,
$this->customStaticProperties,
$this->customConstants,
$this->className
);
}
return $this;
} | [
"public",
"function",
"finalize",
"(",
")",
":",
"self",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isFinalized",
")",
"{",
"$",
"this",
"->",
"normalizeDefinition",
"(",
")",
";",
"$",
"this",
"->",
"isFinalized",
"=",
"true",
";",
"$",
"this",
"->",
... | Finalize the mock builder.
@return $this This builder. | [
"Finalize",
"the",
"mock",
"builder",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L390-L407 |
41,920 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.build | public function build(bool $createNew = false): ReflectionClass
{
if (!$this->class) {
$this->class = $this->factory
->createMockClass($this->definition(), $createNew);
}
return $this->class;
} | php | public function build(bool $createNew = false): ReflectionClass
{
if (!$this->class) {
$this->class = $this->factory
->createMockClass($this->definition(), $createNew);
}
return $this->class;
} | [
"public",
"function",
"build",
"(",
"bool",
"$",
"createNew",
"=",
"false",
")",
":",
"ReflectionClass",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"class",
")",
"{",
"$",
"this",
"->",
"class",
"=",
"$",
"this",
"->",
"factory",
"->",
"createMockClass",
... | Generate and define the mock class.
Calling this method will finalize the mock builder.
@param bool $createNew True if a new class should be created even when a compatible one exists.
@return ReflectionClass The class.
@throws MockException If the mock generation fails. | [
"Generate",
"and",
"define",
"the",
"mock",
"class",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L443-L451 |
41,921 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.get | public function get(): Mock
{
if ($this->mock) {
return $this->mock;
}
$this->mock = $this->factory->createFullMock($this->build());
return $this->mock;
} | php | public function get(): Mock
{
if ($this->mock) {
return $this->mock;
}
$this->mock = $this->factory->createFullMock($this->build());
return $this->mock;
} | [
"public",
"function",
"get",
"(",
")",
":",
"Mock",
"{",
"if",
"(",
"$",
"this",
"->",
"mock",
")",
"{",
"return",
"$",
"this",
"->",
"mock",
";",
"}",
"$",
"this",
"->",
"mock",
"=",
"$",
"this",
"->",
"factory",
"->",
"createFullMock",
"(",
"$"... | Get a mock.
This method will return the current mock, only creating a new mock if no
existing mock is available.
If no existing mock is available, the created mock will be a full mock.
Calling this method will finalize the mock builder.
@return Mock The mock instance.
@throws MockException If the mock generation fails. | [
"Get",
"a",
"mock",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L481-L490 |
41,922 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.full | public function full(): Mock
{
$this->mock = $this->factory->createFullMock($this->build());
return $this->mock;
} | php | public function full(): Mock
{
$this->mock = $this->factory->createFullMock($this->build());
return $this->mock;
} | [
"public",
"function",
"full",
"(",
")",
":",
"Mock",
"{",
"$",
"this",
"->",
"mock",
"=",
"$",
"this",
"->",
"factory",
"->",
"createFullMock",
"(",
"$",
"this",
"->",
"build",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"mock",
";",
"}"
] | Create a new full mock.
This method will always create a new mock, and will replace the current
mock.
Calling this method will finalize the mock builder.
@return Mock The mock instance.
@throws MockException If the mock generation fails. | [
"Create",
"a",
"new",
"full",
"mock",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L503-L508 |
41,923 | eloquent/phony | src/Mock/Builder/MockBuilder.php | MockBuilder.source | public function source(MockGenerator $generator = null): string
{
if (!$generator) {
$generator = MockGenerator::instance();
}
return $generator->generate($this->definition());
} | php | public function source(MockGenerator $generator = null): string
{
if (!$generator) {
$generator = MockGenerator::instance();
}
return $generator->generate($this->definition());
} | [
"public",
"function",
"source",
"(",
"MockGenerator",
"$",
"generator",
"=",
"null",
")",
":",
"string",
"{",
"if",
"(",
"!",
"$",
"generator",
")",
"{",
"$",
"generator",
"=",
"MockGenerator",
"::",
"instance",
"(",
")",
";",
"}",
"return",
"$",
"gene... | Get the generated source code of the mock class.
Calling this method will finalize the mock builder.
@param MockGenerator|null $generator The mock generator to use.
@return string The source code.
@throws MockException If the mock generation fails. | [
"Get",
"the",
"generated",
"source",
"code",
"of",
"the",
"mock",
"class",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/MockBuilder.php#L564-L571 |
41,924 | eloquent/phony | src/Verification/GeneratorVerifierFactory.php | GeneratorVerifierFactory.create | public function create($subject, array $calls): GeneratorVerifier
{
return new GeneratorVerifier(
$subject,
$calls,
$this->matcherFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | php | public function create($subject, array $calls): GeneratorVerifier
{
return new GeneratorVerifier(
$subject,
$calls,
$this->matcherFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | [
"public",
"function",
"create",
"(",
"$",
"subject",
",",
"array",
"$",
"calls",
")",
":",
"GeneratorVerifier",
"{",
"return",
"new",
"GeneratorVerifier",
"(",
"$",
"subject",
",",
"$",
"calls",
",",
"$",
"this",
"->",
"matcherFactory",
",",
"$",
"this",
... | Create a new generator verifier.
@param Spy|Call $subject The subject.
@param array<Call> $calls The calls.
@return GeneratorVerifier The newly created generator verifier. | [
"Create",
"a",
"new",
"generator",
"verifier",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Verification/GeneratorVerifierFactory.php#L74-L84 |
41,925 | eloquent/phony | src/Matcher/MatcherFactory.php | MatcherFactory.addMatcherDriver | public function addMatcherDriver(MatcherDriver $driver): void
{
if (!in_array($driver, $this->drivers, true)) {
$this->drivers[] = $driver;
if ($driver->isAvailable()) {
foreach ($driver->matcherClassNames() as $className) {
$this->driverIndex[$className] = $driver;
}
}
}
} | php | public function addMatcherDriver(MatcherDriver $driver): void
{
if (!in_array($driver, $this->drivers, true)) {
$this->drivers[] = $driver;
if ($driver->isAvailable()) {
foreach ($driver->matcherClassNames() as $className) {
$this->driverIndex[$className] = $driver;
}
}
}
} | [
"public",
"function",
"addMatcherDriver",
"(",
"MatcherDriver",
"$",
"driver",
")",
":",
"void",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"driver",
",",
"$",
"this",
"->",
"drivers",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"drivers",
"[",
"]... | Add a matcher driver.
@param MatcherDriver $driver The matcher driver. | [
"Add",
"a",
"matcher",
"driver",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L60-L71 |
41,926 | eloquent/phony | src/Matcher/MatcherFactory.php | MatcherFactory.isMatcher | public function isMatcher($value): bool
{
if (is_object($value)) {
if ($value instanceof Matcher) {
return true;
}
foreach ($this->driverIndex as $className => $driver) {
if (is_a($value, $className)) {
return true;
}
}
}
return false;
} | php | public function isMatcher($value): bool
{
if (is_object($value)) {
if ($value instanceof Matcher) {
return true;
}
foreach ($this->driverIndex as $className => $driver) {
if (is_a($value, $className)) {
return true;
}
}
}
return false;
} | [
"public",
"function",
"isMatcher",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Matcher",
")",
"{",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"thi... | Returns true if the supplied value is a matcher.
@param mixed $value The value to test.
@return bool True if the value is a matcher. | [
"Returns",
"true",
"if",
"the",
"supplied",
"value",
"is",
"a",
"matcher",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L90-L105 |
41,927 | eloquent/phony | src/Matcher/MatcherFactory.php | MatcherFactory.adapt | public function adapt($value): Matchable
{
if ($value instanceof Matchable) {
return $value;
}
if (is_object($value)) {
foreach ($this->driverIndex as $className => $driver) {
if (is_a($value, $className)) {
return $driver->wrapMatcher($value);
}
}
}
if ('*' === $value) {
return $this->wildcardAnyMatcher;
}
if ('~' === $value) {
return $this->anyMatcher;
}
return new EqualToMatcher($value, true, $this->exporter);
} | php | public function adapt($value): Matchable
{
if ($value instanceof Matchable) {
return $value;
}
if (is_object($value)) {
foreach ($this->driverIndex as $className => $driver) {
if (is_a($value, $className)) {
return $driver->wrapMatcher($value);
}
}
}
if ('*' === $value) {
return $this->wildcardAnyMatcher;
}
if ('~' === $value) {
return $this->anyMatcher;
}
return new EqualToMatcher($value, true, $this->exporter);
} | [
"public",
"function",
"adapt",
"(",
"$",
"value",
")",
":",
"Matchable",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Matchable",
")",
"{",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"foreach",
"(",
... | Create a new matcher for the supplied value.
@param mixed $value The value to create a matcher for.
@return Matchable The newly created matcher. | [
"Create",
"a",
"new",
"matcher",
"for",
"the",
"supplied",
"value",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L114-L137 |
41,928 | eloquent/phony | src/Matcher/MatcherFactory.php | MatcherFactory.adaptAll | public function adaptAll(array $values): array
{
$matchers = [];
foreach ($values as $value) {
if (
$value instanceof Matcher ||
$value instanceof WildcardMatcher
) {
$matchers[] = $value;
continue;
}
if (is_object($value)) {
foreach ($this->driverIndex as $className => $driver) {
if (is_a($value, $className)) {
$matchers[] = $driver->wrapMatcher($value);
continue 2;
}
}
}
if ('*' === $value) {
$matchers[] = $this->wildcardAnyMatcher;
} elseif ('~' === $value) {
$matchers[] = $this->anyMatcher;
} else {
$matchers[] = new EqualToMatcher($value, true, $this->exporter);
}
}
return $matchers;
} | php | public function adaptAll(array $values): array
{
$matchers = [];
foreach ($values as $value) {
if (
$value instanceof Matcher ||
$value instanceof WildcardMatcher
) {
$matchers[] = $value;
continue;
}
if (is_object($value)) {
foreach ($this->driverIndex as $className => $driver) {
if (is_a($value, $className)) {
$matchers[] = $driver->wrapMatcher($value);
continue 2;
}
}
}
if ('*' === $value) {
$matchers[] = $this->wildcardAnyMatcher;
} elseif ('~' === $value) {
$matchers[] = $this->anyMatcher;
} else {
$matchers[] = new EqualToMatcher($value, true, $this->exporter);
}
}
return $matchers;
} | [
"public",
"function",
"adaptAll",
"(",
"array",
"$",
"values",
")",
":",
"array",
"{",
"$",
"matchers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"instanceof",
"Matcher",
"||",
"$",
"v... | Create new matchers for the all supplied values.
@param array $values The values to create matchers for.
@return array<Matchable> The newly created matchers. | [
"Create",
"new",
"matchers",
"for",
"the",
"all",
"supplied",
"values",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Matcher/MatcherFactory.php#L146-L180 |
41,929 | eloquent/phony | src/Spy/IterableSpyFactory.php | IterableSpyFactory.create | public function create(Call $call, $iterable): IterableSpy
{
if ($iterable instanceof Traversable) {
return new TraversableSpy(
$call,
$iterable,
$this->callEventFactory
);
}
if (is_array($iterable)) {
return new ArraySpy($call, $iterable, $this->callEventFactory);
}
if (is_object($iterable)) {
$type = var_export(get_class($iterable), true);
} else {
$type = gettype($iterable);
}
throw new InvalidArgumentException(
sprintf('Unsupported iterable of type %s.', $type)
);
} | php | public function create(Call $call, $iterable): IterableSpy
{
if ($iterable instanceof Traversable) {
return new TraversableSpy(
$call,
$iterable,
$this->callEventFactory
);
}
if (is_array($iterable)) {
return new ArraySpy($call, $iterable, $this->callEventFactory);
}
if (is_object($iterable)) {
$type = var_export(get_class($iterable), true);
} else {
$type = gettype($iterable);
}
throw new InvalidArgumentException(
sprintf('Unsupported iterable of type %s.', $type)
);
} | [
"public",
"function",
"create",
"(",
"Call",
"$",
"call",
",",
"$",
"iterable",
")",
":",
"IterableSpy",
"{",
"if",
"(",
"$",
"iterable",
"instanceof",
"Traversable",
")",
"{",
"return",
"new",
"TraversableSpy",
"(",
"$",
"call",
",",
"$",
"iterable",
",... | Create a new iterable spy.
@param Call $call The call from which the iterable originated.
@param iterable $iterable The iterable.
@return IterableSpy The newly created iterable spy.
@throws InvalidArgumentException If the supplied iterable is invalid. | [
"Create",
"a",
"new",
"iterable",
"spy",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/IterableSpyFactory.php#L50-L73 |
41,930 | eloquent/phony | src/Reflection/FeatureDetector.php | FeatureDetector.isSupported | public function isSupported(string $feature): bool
{
if (!array_key_exists($feature, $this->supported)) {
if (!isset($this->features[$feature])) {
throw new UndefinedFeatureException($feature);
}
$this->supported[$feature] =
(bool) $this->features[$feature]($this);
}
return $this->supported[$feature];
} | php | public function isSupported(string $feature): bool
{
if (!array_key_exists($feature, $this->supported)) {
if (!isset($this->features[$feature])) {
throw new UndefinedFeatureException($feature);
}
$this->supported[$feature] =
(bool) $this->features[$feature]($this);
}
return $this->supported[$feature];
} | [
"public",
"function",
"isSupported",
"(",
"string",
"$",
"feature",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"feature",
",",
"$",
"this",
"->",
"supported",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
... | Returns true if the specified feature is supported by the current
runtime environment.
@param string $feature The feature.
@return bool True if supported.
@throws UndefinedFeatureException If the specified feature is undefined. | [
"Returns",
"true",
"if",
"the",
"specified",
"feature",
"is",
"supported",
"by",
"the",
"current",
"runtime",
"environment",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Reflection/FeatureDetector.php#L91-L103 |
41,931 | eloquent/phony | src/Reflection/FeatureDetector.php | FeatureDetector.standardFeatures | public function standardFeatures(): array
{
return [
'stdout.ansi' => function () {
// @codeCoverageIgnoreStart
if (DIRECTORY_SEPARATOR === '\\') {
return
0 >= version_compare(
'10.0.10586',
PHP_WINDOWS_VERSION_MAJOR .
'.' . PHP_WINDOWS_VERSION_MINOR .
'.' . PHP_WINDOWS_VERSION_BUILD
) ||
false !== getenv('ANSICON') ||
'ON' === getenv('ConEmuANSI') ||
'xterm' === getenv('TERM') ||
false !== getenv('BABUN_HOME');
}
// @codeCoverageIgnoreEnd
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
},
'type.object' => function () {
try {
$function =
new ReflectionFunction(function (object $a) {});
$parameters = $function->getParameters();
$result = null === $parameters[0]->getClass();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
$result = false;
}
// @codeCoverageIgnoreEnd
return $result;
},
];
} | php | public function standardFeatures(): array
{
return [
'stdout.ansi' => function () {
// @codeCoverageIgnoreStart
if (DIRECTORY_SEPARATOR === '\\') {
return
0 >= version_compare(
'10.0.10586',
PHP_WINDOWS_VERSION_MAJOR .
'.' . PHP_WINDOWS_VERSION_MINOR .
'.' . PHP_WINDOWS_VERSION_BUILD
) ||
false !== getenv('ANSICON') ||
'ON' === getenv('ConEmuANSI') ||
'xterm' === getenv('TERM') ||
false !== getenv('BABUN_HOME');
}
// @codeCoverageIgnoreEnd
return function_exists('posix_isatty') && @posix_isatty(STDOUT);
},
'type.object' => function () {
try {
$function =
new ReflectionFunction(function (object $a) {});
$parameters = $function->getParameters();
$result = null === $parameters[0]->getClass();
// @codeCoverageIgnoreStart
} catch (ReflectionException $e) {
$result = false;
}
// @codeCoverageIgnoreEnd
return $result;
},
];
} | [
"public",
"function",
"standardFeatures",
"(",
")",
":",
"array",
"{",
"return",
"[",
"'stdout.ansi'",
"=>",
"function",
"(",
")",
"{",
"// @codeCoverageIgnoreStart",
"if",
"(",
"DIRECTORY_SEPARATOR",
"===",
"'\\\\'",
")",
"{",
"return",
"0",
">=",
"version_comp... | Get the standard feature detection callbacks.
@return array<string,callable> The standard features. | [
"Get",
"the",
"standard",
"feature",
"detection",
"callbacks",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Reflection/FeatureDetector.php#L110-L148 |
41,932 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.calls | public function calls(callable ...$callbacks): self
{
foreach ($callbacks as $callback) {
$this->callsWith($callback);
}
return $this;
} | php | public function calls(callable ...$callbacks): self
{
foreach ($callbacks as $callback) {
$this->callsWith($callback);
}
return $this;
} | [
"public",
"function",
"calls",
"(",
"callable",
"...",
"$",
"callbacks",
")",
":",
"self",
"{",
"foreach",
"(",
"$",
"callbacks",
"as",
"$",
"callback",
")",
"{",
"$",
"this",
"->",
"callsWith",
"(",
"$",
"callback",
")",
";",
"}",
"return",
"$",
"th... | Add a callback to be called as part of the answer.
@param callable ...$callbacks The callbacks.
@return $this This builder. | [
"Add",
"a",
"callback",
"to",
"be",
"called",
"as",
"part",
"of",
"the",
"answer",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L49-L56 |
41,933 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.setsArgument | public function setsArgument($indexOrValue = null, $value = null): self
{
if (func_num_args() > 1) {
$index = $indexOrValue;
} else {
$index = 0;
$value = $indexOrValue;
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
return $this->callsWith(
function ($arguments) use ($index, $value) {
$arguments->set($index, $value);
},
[],
false,
true,
false
);
} | php | public function setsArgument($indexOrValue = null, $value = null): self
{
if (func_num_args() > 1) {
$index = $indexOrValue;
} else {
$index = 0;
$value = $indexOrValue;
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
return $this->callsWith(
function ($arguments) use ($index, $value) {
$arguments->set($index, $value);
},
[],
false,
true,
false
);
} | [
"public",
"function",
"setsArgument",
"(",
"$",
"indexOrValue",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"if",
"(",
"func_num_args",
"(",
")",
">",
"1",
")",
"{",
"$",
"index",
"=",
"$",
"indexOrValue",
";",
"}",
"else",
... | Set the value of an argument passed by reference as part of the answer.
If called with no arguments, sets the first argument to null.
If called with one argument, sets the first argument to $indexOrValue.
If called with two arguments, sets the argument at $indexOrValue to
$value.
@param mixed $indexOrValue The index, or value if no index is specified.
@param mixed $value The value.
@return $this This builder. | [
"Set",
"the",
"value",
"of",
"an",
"argument",
"passed",
"by",
"reference",
"as",
"part",
"of",
"the",
"answer",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L198-L220 |
41,934 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.yields | public function yields($keyOrValue = null, $value = null): self
{
$argumentCount = func_num_args();
if ($argumentCount > 1) {
$hasKey = true;
$hasValue = true;
$key = $keyOrValue;
} elseif ($argumentCount > 0) {
$hasKey = false;
$hasValue = true;
$key = null;
$value = $keyOrValue;
} else {
$hasKey = false;
$hasValue = false;
$key = null;
}
if ($key instanceof InstanceHandle) {
$key = $key->get();
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
$this->iterations[] = new GeneratorYieldIteration(
$this->requests,
$hasKey,
$key,
$hasValue,
$value
);
$this->requests = [];
return $this;
} | php | public function yields($keyOrValue = null, $value = null): self
{
$argumentCount = func_num_args();
if ($argumentCount > 1) {
$hasKey = true;
$hasValue = true;
$key = $keyOrValue;
} elseif ($argumentCount > 0) {
$hasKey = false;
$hasValue = true;
$key = null;
$value = $keyOrValue;
} else {
$hasKey = false;
$hasValue = false;
$key = null;
}
if ($key instanceof InstanceHandle) {
$key = $key->get();
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
$this->iterations[] = new GeneratorYieldIteration(
$this->requests,
$hasKey,
$key,
$hasValue,
$value
);
$this->requests = [];
return $this;
} | [
"public",
"function",
"yields",
"(",
"$",
"keyOrValue",
"=",
"null",
",",
"$",
"value",
"=",
"null",
")",
":",
"self",
"{",
"$",
"argumentCount",
"=",
"func_num_args",
"(",
")",
";",
"if",
"(",
"$",
"argumentCount",
">",
"1",
")",
"{",
"$",
"hasKey",... | Add a yielded value to the answer.
If both `$keyOrValue` and `$value` are supplied, the stub will yield like
`yield $keyOrValue => $value;`.
If only `$keyOrValue` is supplied, the stub will yield like
`yield $keyOrValue;`.
If no arguments are supplied, the stub will yield like `yield;`.
@param mixed $keyOrValue The key or value.
@param mixed $value The value.
@return $this This builder. | [
"Add",
"a",
"yielded",
"value",
"to",
"the",
"answer",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L238-L275 |
41,935 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.yieldsFrom | public function yieldsFrom($values): self
{
$this->iterations[] =
new GeneratorYieldFromIteration($this->requests, $values);
$this->requests = [];
return $this;
} | php | public function yieldsFrom($values): self
{
$this->iterations[] =
new GeneratorYieldFromIteration($this->requests, $values);
$this->requests = [];
return $this;
} | [
"public",
"function",
"yieldsFrom",
"(",
"$",
"values",
")",
":",
"self",
"{",
"$",
"this",
"->",
"iterations",
"[",
"]",
"=",
"new",
"GeneratorYieldFromIteration",
"(",
"$",
"this",
"->",
"requests",
",",
"$",
"values",
")",
";",
"$",
"this",
"->",
"r... | Add a set of yielded values to the answer.
@param mixed<mixed,mixed> $values The set of keys and values to yield.
@return $this This builder. | [
"Add",
"a",
"set",
"of",
"yielded",
"values",
"to",
"the",
"answer",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L284-L291 |
41,936 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.returns | public function returns(...$values): Stub
{
if (empty($values)) {
$values = [null];
}
$value = $values[0];
$argumentCount = count($values);
$copies = [];
for ($i = 1; $i < $argumentCount; ++$i) {
$copies[$i] = clone $this;
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
$this->returnValue = $value;
$this->returnsArgument = null;
$this->returnsSelf = false;
for ($i = 1; $i < $argumentCount; ++$i) {
$this->stub
->doesWith($copies[$i]->answer(), [], true, true, false);
$copies[$i]->returns($values[$i]);
}
return $this->stub;
} | php | public function returns(...$values): Stub
{
if (empty($values)) {
$values = [null];
}
$value = $values[0];
$argumentCount = count($values);
$copies = [];
for ($i = 1; $i < $argumentCount; ++$i) {
$copies[$i] = clone $this;
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
$this->returnValue = $value;
$this->returnsArgument = null;
$this->returnsSelf = false;
for ($i = 1; $i < $argumentCount; ++$i) {
$this->stub
->doesWith($copies[$i]->answer(), [], true, true, false);
$copies[$i]->returns($values[$i]);
}
return $this->stub;
} | [
"public",
"function",
"returns",
"(",
"...",
"$",
"values",
")",
":",
"Stub",
"{",
"if",
"(",
"empty",
"(",
"$",
"values",
")",
")",
"{",
"$",
"values",
"=",
"[",
"null",
"]",
";",
"}",
"$",
"value",
"=",
"$",
"values",
"[",
"0",
"]",
";",
"$... | End the generator by returning a value.
Calling this method with no arguments is equivalent to calling it with a
single argument of `null`.
@param mixed ...$values The return values.
@return Stub The stub. | [
"End",
"the",
"generator",
"by",
"returning",
"a",
"value",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L303-L333 |
41,937 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.throws | public function throws(...$exceptions): Stub
{
if (empty($exceptions)) {
$exceptions = [new Exception()];
}
$exception = $exceptions[0];
$argumentCount = count($exceptions);
$copies = [];
for ($i = 1; $i < $argumentCount; ++$i) {
$copies[$i] = clone $this;
}
if (is_string($exception)) {
$exception = new Exception($exception);
} elseif ($exception instanceof InstanceHandle) {
$exception = $exception->get();
}
$this->exception = $exception;
for ($i = 1; $i < $argumentCount; ++$i) {
$this->stub
->doesWith($copies[$i]->answer(), [], true, true, false);
$copies[$i]->throws($exceptions[$i]);
}
return $this->stub;
} | php | public function throws(...$exceptions): Stub
{
if (empty($exceptions)) {
$exceptions = [new Exception()];
}
$exception = $exceptions[0];
$argumentCount = count($exceptions);
$copies = [];
for ($i = 1; $i < $argumentCount; ++$i) {
$copies[$i] = clone $this;
}
if (is_string($exception)) {
$exception = new Exception($exception);
} elseif ($exception instanceof InstanceHandle) {
$exception = $exception->get();
}
$this->exception = $exception;
for ($i = 1; $i < $argumentCount; ++$i) {
$this->stub
->doesWith($copies[$i]->answer(), [], true, true, false);
$copies[$i]->throws($exceptions[$i]);
}
return $this->stub;
} | [
"public",
"function",
"throws",
"(",
"...",
"$",
"exceptions",
")",
":",
"Stub",
"{",
"if",
"(",
"empty",
"(",
"$",
"exceptions",
")",
")",
"{",
"$",
"exceptions",
"=",
"[",
"new",
"Exception",
"(",
")",
"]",
";",
"}",
"$",
"exception",
"=",
"$",
... | End the generator by throwing an exception.
Calling this method with no arguments is equivalent to calling it with a
single argument of `null`.
@param Throwable|string|null ...$exceptions The exceptions, or messages, or nulls to throw generic exceptions.
@return Stub The stub. | [
"End",
"the",
"generator",
"by",
"throwing",
"an",
"exception",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L374-L404 |
41,938 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilder.php | GeneratorAnswerBuilder.answer | public function answer(): callable
{
return function ($self, $arguments) {
foreach ($this->iterations as $iteration) {
foreach ($iteration->requests as $request) {
$this->invoker->callWith(
$request->callback(),
$request->finalArguments($self, $arguments)
);
}
if ($iteration instanceof GeneratorYieldFromIteration) {
foreach ($iteration->values as $key => $value) {
if ($key instanceof InstanceHandle) {
$key = $key->get();
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
yield $key => $value;
}
} else {
if ($iteration->hasKey) {
yield $iteration->key => $iteration->value;
} elseif ($iteration->hasValue) {
yield $iteration->value;
} else {
yield;
}
}
}
foreach ($this->requests as $request) {
$this->invoker->callWith(
$request->callback(),
$request->finalArguments($self, $arguments)
);
}
if ($this->exception) {
throw $this->exception;
}
if ($this->returnsSelf) {
return $self;
}
if (null !== $this->returnsArgument) {
return $arguments->get($this->returnsArgument);
}
return $this->returnValue;
};
} | php | public function answer(): callable
{
return function ($self, $arguments) {
foreach ($this->iterations as $iteration) {
foreach ($iteration->requests as $request) {
$this->invoker->callWith(
$request->callback(),
$request->finalArguments($self, $arguments)
);
}
if ($iteration instanceof GeneratorYieldFromIteration) {
foreach ($iteration->values as $key => $value) {
if ($key instanceof InstanceHandle) {
$key = $key->get();
}
if ($value instanceof InstanceHandle) {
$value = $value->get();
}
yield $key => $value;
}
} else {
if ($iteration->hasKey) {
yield $iteration->key => $iteration->value;
} elseif ($iteration->hasValue) {
yield $iteration->value;
} else {
yield;
}
}
}
foreach ($this->requests as $request) {
$this->invoker->callWith(
$request->callback(),
$request->finalArguments($self, $arguments)
);
}
if ($this->exception) {
throw $this->exception;
}
if ($this->returnsSelf) {
return $self;
}
if (null !== $this->returnsArgument) {
return $arguments->get($this->returnsArgument);
}
return $this->returnValue;
};
} | [
"public",
"function",
"answer",
"(",
")",
":",
"callable",
"{",
"return",
"function",
"(",
"$",
"self",
",",
"$",
"arguments",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"iterations",
"as",
"$",
"iteration",
")",
"{",
"foreach",
"(",
"$",
"iteration"... | Get the answer.
@return callable The answer. | [
"Get",
"the",
"answer",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilder.php#L411-L466 |
41,939 | eloquent/phony | src/Call/CallFactory.php | CallFactory.record | public function record(
$callback,
Arguments $arguments,
SpyData $spy
): CallData {
$originalArguments = $arguments->copy();
$call = new CallData(
$spy->nextIndex(),
$this->eventFactory->createCalled($spy, $originalArguments)
);
$spy->addCall($call);
$returnValue = null;
$exception = null;
try {
$returnValue = $this->invoker->callWith($callback, $arguments);
} catch (Throwable $exception) {
// handled below
}
if ($exception) {
$responseEvent = $this->eventFactory->createThrew($exception);
} else {
$responseEvent = $this->eventFactory->createReturned($returnValue);
}
$call->setResponseEvent($responseEvent);
return $call;
} | php | public function record(
$callback,
Arguments $arguments,
SpyData $spy
): CallData {
$originalArguments = $arguments->copy();
$call = new CallData(
$spy->nextIndex(),
$this->eventFactory->createCalled($spy, $originalArguments)
);
$spy->addCall($call);
$returnValue = null;
$exception = null;
try {
$returnValue = $this->invoker->callWith($callback, $arguments);
} catch (Throwable $exception) {
// handled below
}
if ($exception) {
$responseEvent = $this->eventFactory->createThrew($exception);
} else {
$responseEvent = $this->eventFactory->createReturned($returnValue);
}
$call->setResponseEvent($responseEvent);
return $call;
} | [
"public",
"function",
"record",
"(",
"$",
"callback",
",",
"Arguments",
"$",
"arguments",
",",
"SpyData",
"$",
"spy",
")",
":",
"CallData",
"{",
"$",
"originalArguments",
"=",
"$",
"arguments",
"->",
"copy",
"(",
")",
";",
"$",
"call",
"=",
"new",
"Cal... | Record call details by invoking a callback.
@param callable $callback The callback.
@param Arguments $arguments The arguments.
@param SpyData $spy The spy to record the call to.
@return CallData The newly created call. | [
"Record",
"call",
"details",
"by",
"invoking",
"a",
"callback",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallFactory.php#L57-L88 |
41,940 | eloquent/phony | src/Stub/Answer/CallRequest.php | CallRequest.finalArguments | public function finalArguments($self, Arguments $arguments): Arguments
{
$finalArguments = $this->arguments->all();
if ($this->prefixSelf) {
array_unshift($finalArguments, $self);
}
if ($this->suffixArgumentsObject) {
$finalArguments[] = $arguments;
}
if ($this->suffixArguments && $arguments) {
$finalArguments = array_merge($finalArguments, $arguments->all());
}
return new Arguments($finalArguments);
} | php | public function finalArguments($self, Arguments $arguments): Arguments
{
$finalArguments = $this->arguments->all();
if ($this->prefixSelf) {
array_unshift($finalArguments, $self);
}
if ($this->suffixArgumentsObject) {
$finalArguments[] = $arguments;
}
if ($this->suffixArguments && $arguments) {
$finalArguments = array_merge($finalArguments, $arguments->all());
}
return new Arguments($finalArguments);
} | [
"public",
"function",
"finalArguments",
"(",
"$",
"self",
",",
"Arguments",
"$",
"arguments",
")",
":",
"Arguments",
"{",
"$",
"finalArguments",
"=",
"$",
"this",
"->",
"arguments",
"->",
"all",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"prefixSelf",
... | Get the final arguments.
@param object $self The self value.
@param Arguments $arguments The incoming arguments.
@return Arguments The final arguments. | [
"Get",
"the",
"final",
"arguments",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/CallRequest.php#L62-L78 |
41,941 | eloquent/phony | src/Stub/Answer/Builder/GeneratorAnswerBuilderFactory.php | GeneratorAnswerBuilderFactory.create | public function create(Stub $stub): GeneratorAnswerBuilder
{
return new GeneratorAnswerBuilder(
$stub,
$this->invocableInspector,
$this->invoker
);
} | php | public function create(Stub $stub): GeneratorAnswerBuilder
{
return new GeneratorAnswerBuilder(
$stub,
$this->invocableInspector,
$this->invoker
);
} | [
"public",
"function",
"create",
"(",
"Stub",
"$",
"stub",
")",
":",
"GeneratorAnswerBuilder",
"{",
"return",
"new",
"GeneratorAnswerBuilder",
"(",
"$",
"stub",
",",
"$",
"this",
"->",
"invocableInspector",
",",
"$",
"this",
"->",
"invoker",
")",
";",
"}"
] | Create a generator answer builder for the supplied stub.
@param Stub $stub The stub.
@return GeneratorAnswerBuilder The newly created builder. | [
"Create",
"a",
"generator",
"answer",
"builder",
"for",
"the",
"supplied",
"stub",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/Answer/Builder/GeneratorAnswerBuilderFactory.php#L54-L61 |
41,942 | eloquent/phony | src/Call/CallVerifierFactory.php | CallVerifierFactory.fromCall | public function fromCall(Call $call): CallVerifier
{
return new CallVerifier(
$call,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | php | public function fromCall(Call $call): CallVerifier
{
return new CallVerifier(
$call,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | [
"public",
"function",
"fromCall",
"(",
"Call",
"$",
"call",
")",
":",
"CallVerifier",
"{",
"return",
"new",
"CallVerifier",
"(",
"$",
"call",
",",
"$",
"this",
"->",
"matcherFactory",
",",
"$",
"this",
"->",
"matcherVerifier",
",",
"$",
"this",
"->",
"ge... | Wrap the supplied call in a verifier.
@param Call $call The call.
@return CallVerifier The call verifier. | [
"Wrap",
"the",
"supplied",
"call",
"in",
"a",
"verifier",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifierFactory.php#L74-L85 |
41,943 | eloquent/phony | src/Call/CallVerifierFactory.php | CallVerifierFactory.fromCalls | public function fromCalls(array $calls): array
{
$verifiers = [];
foreach ($calls as $call) {
$verifiers[] = new CallVerifier(
$call,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
}
return $verifiers;
} | php | public function fromCalls(array $calls): array
{
$verifiers = [];
foreach ($calls as $call) {
$verifiers[] = new CallVerifier(
$call,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
}
return $verifiers;
} | [
"public",
"function",
"fromCalls",
"(",
"array",
"$",
"calls",
")",
":",
"array",
"{",
"$",
"verifiers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"calls",
"as",
"$",
"call",
")",
"{",
"$",
"verifiers",
"[",
"]",
"=",
"new",
"CallVerifier",
"(",
"$"... | Wrap the supplied calls in verifiers.
@param array<Call> $calls The calls.
@return array<CallVerifier> The call verifiers. | [
"Wrap",
"the",
"supplied",
"calls",
"in",
"verifiers",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallVerifierFactory.php#L94-L111 |
41,944 | eloquent/phony | src/Invocation/Invoker.php | Invoker.callWith | public function callWith($callback, Arguments $arguments)
{
if ($callback instanceof Invocable) {
return $callback->invokeWith($arguments);
}
$arguments = $arguments->all();
return $callback(...$arguments);
} | php | public function callWith($callback, Arguments $arguments)
{
if ($callback instanceof Invocable) {
return $callback->invokeWith($arguments);
}
$arguments = $arguments->all();
return $callback(...$arguments);
} | [
"public",
"function",
"callWith",
"(",
"$",
"callback",
",",
"Arguments",
"$",
"arguments",
")",
"{",
"if",
"(",
"$",
"callback",
"instanceof",
"Invocable",
")",
"{",
"return",
"$",
"callback",
"->",
"invokeWith",
"(",
"$",
"arguments",
")",
";",
"}",
"$... | Calls a callback, maintaining reference parameters.
@param callable $callback The callback.
@param Arguments $arguments The arguments.
@return mixed The result of invocation.
@throws Throwable If an error occurs. | [
"Calls",
"a",
"callback",
"maintaining",
"reference",
"parameters",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Invocation/Invoker.php#L38-L47 |
41,945 | eloquent/phony | src/Call/CallData.php | CallData.compareSequential | public static function compareSequential(Call $a, Call $b): int
{
return $a->sequenceNumber() <=> $b->sequenceNumber();
} | php | public static function compareSequential(Call $a, Call $b): int
{
return $a->sequenceNumber() <=> $b->sequenceNumber();
} | [
"public",
"static",
"function",
"compareSequential",
"(",
"Call",
"$",
"a",
",",
"Call",
"$",
"b",
")",
":",
"int",
"{",
"return",
"$",
"a",
"->",
"sequenceNumber",
"(",
")",
"<=>",
"$",
"b",
"->",
"sequenceNumber",
"(",
")",
";",
"}"
] | A comparator for ordering calls by sequence number.
@param Call $a The first call.
@param Call $b The second call.
@return int The comparison value. | [
"A",
"comparator",
"for",
"ordering",
"calls",
"by",
"sequence",
"number",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L37-L40 |
41,946 | eloquent/phony | src/Call/CallData.php | CallData.setResponseEvent | public function setResponseEvent(ResponseEvent $responseEvent): void
{
if ($this->responseEvent) {
throw new InvalidArgumentException('Call already responded.');
}
$responseEvent->setCall($this);
$this->responseEvent = $responseEvent;
} | php | public function setResponseEvent(ResponseEvent $responseEvent): void
{
if ($this->responseEvent) {
throw new InvalidArgumentException('Call already responded.');
}
$responseEvent->setCall($this);
$this->responseEvent = $responseEvent;
} | [
"public",
"function",
"setResponseEvent",
"(",
"ResponseEvent",
"$",
"responseEvent",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"responseEvent",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Call already responded.'",
")",
";",
"}",
"$"... | Set the response event.
@param ResponseEvent $responseEvent The response event.
@throws InvalidArgumentException If the call has already responded. | [
"Set",
"the",
"response",
"event",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L281-L289 |
41,947 | eloquent/phony | src/Call/CallData.php | CallData.addIterableEvent | public function addIterableEvent(IterableEvent $iterableEvent): void
{
if (!$this->isIterable()) {
throw new InvalidArgumentException('Not an iterable call.');
}
if ($this->endEvent) {
throw new InvalidArgumentException('Call already completed.');
}
$iterableEvent->setCall($this);
$this->iterableEvents[] = $iterableEvent;
} | php | public function addIterableEvent(IterableEvent $iterableEvent): void
{
if (!$this->isIterable()) {
throw new InvalidArgumentException('Not an iterable call.');
}
if ($this->endEvent) {
throw new InvalidArgumentException('Call already completed.');
}
$iterableEvent->setCall($this);
$this->iterableEvents[] = $iterableEvent;
} | [
"public",
"function",
"addIterableEvent",
"(",
"IterableEvent",
"$",
"iterableEvent",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isIterable",
"(",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Not an iterable call.'",
")",
"... | Add an iterable event.
@param IterableEvent $iterableEvent The iterable event.
@throws InvalidArgumentException If the call has already completed. | [
"Add",
"an",
"iterable",
"event",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L308-L319 |
41,948 | eloquent/phony | src/Call/CallData.php | CallData.setEndEvent | public function setEndEvent(EndEvent $endEvent): void
{
if ($this->endEvent) {
throw new InvalidArgumentException('Call already completed.');
}
$endEvent->setCall($this);
if (!$this->responseEvent) {
$this->responseEvent = $endEvent;
}
$this->endEvent = $endEvent;
} | php | public function setEndEvent(EndEvent $endEvent): void
{
if ($this->endEvent) {
throw new InvalidArgumentException('Call already completed.');
}
$endEvent->setCall($this);
if (!$this->responseEvent) {
$this->responseEvent = $endEvent;
}
$this->endEvent = $endEvent;
} | [
"public",
"function",
"setEndEvent",
"(",
"EndEvent",
"$",
"endEvent",
")",
":",
"void",
"{",
"if",
"(",
"$",
"this",
"->",
"endEvent",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Call already completed.'",
")",
";",
"}",
"$",
"endEvent",
"-... | Set the end event.
@param EndEvent $endEvent The end event.
@throws InvalidArgumentException If the call has already completed. | [
"Set",
"the",
"end",
"event",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L338-L351 |
41,949 | eloquent/phony | src/Call/CallData.php | CallData.allEvents | public function allEvents(): array
{
$events = $this->iterableEvents();
if ($this->endEvent && $this->responseEvent !== $this->endEvent) {
$events[] = $this->endEvent;
}
if ($this->responseEvent) {
array_unshift($events, $this->responseEvent);
}
array_unshift($events, $this->calledEvent);
return $events;
} | php | public function allEvents(): array
{
$events = $this->iterableEvents();
if ($this->endEvent && $this->responseEvent !== $this->endEvent) {
$events[] = $this->endEvent;
}
if ($this->responseEvent) {
array_unshift($events, $this->responseEvent);
}
array_unshift($events, $this->calledEvent);
return $events;
} | [
"public",
"function",
"allEvents",
"(",
")",
":",
"array",
"{",
"$",
"events",
"=",
"$",
"this",
"->",
"iterableEvents",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"endEvent",
"&&",
"$",
"this",
"->",
"responseEvent",
"!==",
"$",
"this",
"->",
"end... | Get all events as an array.
@return array<Event> The events. | [
"Get",
"all",
"events",
"as",
"an",
"array",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L368-L383 |
41,950 | eloquent/phony | src/Call/CallData.php | CallData.isIterable | public function isIterable(): bool
{
if (!$this->responseEvent instanceof ReturnedEvent) {
return false;
}
$returnValue = $this->responseEvent->value();
return is_array($returnValue) || $returnValue instanceof Traversable;
} | php | public function isIterable(): bool
{
if (!$this->responseEvent instanceof ReturnedEvent) {
return false;
}
$returnValue = $this->responseEvent->value();
return is_array($returnValue) || $returnValue instanceof Traversable;
} | [
"public",
"function",
"isIterable",
"(",
")",
":",
"bool",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"responseEvent",
"instanceof",
"ReturnedEvent",
")",
"{",
"return",
"false",
";",
"}",
"$",
"returnValue",
"=",
"$",
"this",
"->",
"responseEvent",
"->",
"... | Returns true if this call has responded with an iterable.
@return bool True if this call has responded with an iterable. | [
"Returns",
"true",
"if",
"this",
"call",
"has",
"responded",
"with",
"an",
"iterable",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L412-L421 |
41,951 | eloquent/phony | src/Call/CallData.php | CallData.generatorResponse | public function generatorResponse(): array
{
if ($this->endEvent instanceof ReturnedEvent) {
return [null, $this->endEvent->value()];
}
if ($this->endEvent instanceof ThrewEvent) {
return [$this->endEvent->exception(), null];
}
throw new UndefinedResponseException(
'The call has not yet responded via generator.'
);
} | php | public function generatorResponse(): array
{
if ($this->endEvent instanceof ReturnedEvent) {
return [null, $this->endEvent->value()];
}
if ($this->endEvent instanceof ThrewEvent) {
return [$this->endEvent->exception(), null];
}
throw new UndefinedResponseException(
'The call has not yet responded via generator.'
);
} | [
"public",
"function",
"generatorResponse",
"(",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"endEvent",
"instanceof",
"ReturnedEvent",
")",
"{",
"return",
"[",
"null",
",",
"$",
"this",
"->",
"endEvent",
"->",
"value",
"(",
")",
"]",
";",
"}"... | Get the response from the generator.
@return tuple<Throwable|null,mixed> A 2-tuple of thrown exception or null, and return value.
@throws UndefinedResponseException If this call has not yet responded via generator. | [
"Get",
"the",
"response",
"from",
"the",
"generator",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Call/CallData.php#L581-L594 |
41,952 | eloquent/phony | src/Mock/Builder/Method/MethodDefinitionCollection.php | MethodDefinitionCollection.methodName | public function methodName(string $name): string
{
$name = strtolower($name);
return $this->methodNames[$name] ?? '';
} | php | public function methodName(string $name): string
{
$name = strtolower($name);
return $this->methodNames[$name] ?? '';
} | [
"public",
"function",
"methodName",
"(",
"string",
"$",
"name",
")",
":",
"string",
"{",
"$",
"name",
"=",
"strtolower",
"(",
"$",
"name",
")",
";",
"return",
"$",
"this",
"->",
"methodNames",
"[",
"$",
"name",
"]",
"??",
"''",
";",
"}"
] | Get the canonical method name for the supplied method name.
@param string $name The method name.
@return string The canonical method name, or an empty string if no such method exists. | [
"Get",
"the",
"canonical",
"method",
"name",
"for",
"the",
"supplied",
"method",
"name",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Builder/Method/MethodDefinitionCollection.php#L66-L71 |
41,953 | eloquent/phony | src/Mock/Handle/HandleFactory.php | HandleFactory.staticHandle | public function staticHandle($class): StaticHandle
{
if ($class instanceof StaticHandle) {
return $class;
}
if ($class instanceof Handle) {
$class = $class->class();
} elseif ($class instanceof Mock) {
$class = new ReflectionClass($class);
} elseif (is_string($class)) {
try {
$class = new ReflectionClass($class);
} catch (ReflectionException $e) {
throw new NonMockClassException($class, $e);
}
} elseif (!$class instanceof ReflectionClass) {
throw new InvalidMockClassException($class);
}
if (!$class->isSubclassOf(Mock::class)) {
throw new NonMockClassException($class->getName());
}
$handleProperty = $class->getProperty('_staticHandle');
$handleProperty->setAccessible(true);
if ($handle = $handleProperty->getValue(null)) {
return $handle;
}
$handle = new StaticHandle(
$class,
(object) [
'defaultAnswerCallback' =>
[StubData::class, 'forwardsAnswerCallback'],
'stubs' => (object) [],
'isRecording' => true,
],
$this->stubFactory,
$this->stubVerifierFactory,
$this->emptyValueFactory,
$this->assertionRenderer,
$this->assertionRecorder,
$this->invoker
);
$handleProperty->setValue(null, $handle);
return $handle;
} | php | public function staticHandle($class): StaticHandle
{
if ($class instanceof StaticHandle) {
return $class;
}
if ($class instanceof Handle) {
$class = $class->class();
} elseif ($class instanceof Mock) {
$class = new ReflectionClass($class);
} elseif (is_string($class)) {
try {
$class = new ReflectionClass($class);
} catch (ReflectionException $e) {
throw new NonMockClassException($class, $e);
}
} elseif (!$class instanceof ReflectionClass) {
throw new InvalidMockClassException($class);
}
if (!$class->isSubclassOf(Mock::class)) {
throw new NonMockClassException($class->getName());
}
$handleProperty = $class->getProperty('_staticHandle');
$handleProperty->setAccessible(true);
if ($handle = $handleProperty->getValue(null)) {
return $handle;
}
$handle = new StaticHandle(
$class,
(object) [
'defaultAnswerCallback' =>
[StubData::class, 'forwardsAnswerCallback'],
'stubs' => (object) [],
'isRecording' => true,
],
$this->stubFactory,
$this->stubVerifierFactory,
$this->emptyValueFactory,
$this->assertionRenderer,
$this->assertionRecorder,
$this->invoker
);
$handleProperty->setValue(null, $handle);
return $handle;
} | [
"public",
"function",
"staticHandle",
"(",
"$",
"class",
")",
":",
"StaticHandle",
"{",
"if",
"(",
"$",
"class",
"instanceof",
"StaticHandle",
")",
"{",
"return",
"$",
"class",
";",
"}",
"if",
"(",
"$",
"class",
"instanceof",
"Handle",
")",
"{",
"$",
"... | Create a new static handle.
@param Mock|Handle|ReflectionClass|string $class The class.
@return StaticHandle The newly created handle.
@throws MockException If the supplied class name is not a mock class. | [
"Create",
"a",
"new",
"static",
"handle",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/HandleFactory.php#L135-L185 |
41,954 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.checkCalled | public function checkCalled(): ?EventCollection
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$callCount = count($calls);
if ($cardinality->matches($callCount, $callCount)) {
return $this->assertionRecorder->createSuccess($calls);
}
return null;
} | php | public function checkCalled(): ?EventCollection
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$callCount = count($calls);
if ($cardinality->matches($callCount, $callCount)) {
return $this->assertionRecorder->createSuccess($calls);
}
return null;
} | [
"public",
"function",
"checkCalled",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"calls",
"=",
"$",
"this",
"->",
"spy",
"->",
"allCalls",
"(",
")",
";",
"$",
"callCoun... | Checks if called.
@return EventCollection|null The result. | [
"Checks",
"if",
"called",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L424-L436 |
41,955 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.called | public function called(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkCalled()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderCalled($this->spy, $cardinality)
);
} | php | public function called(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkCalled()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderCalled($this->spy, $cardinality)
);
} | [
"public",
"function",
"called",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"checkCalled",
"(",
")",
")",
"{",
"return",
"$",
"result",
... | Throws an exception unless called.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"called",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L444-L455 |
41,956 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.responded | public function responded(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkResponded()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderResponded($this->spy, $cardinality)
);
} | php | public function responded(): ?EventCollection
{
$cardinality = $this->cardinality;
if ($result = $this->checkResponded()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderResponded($this->spy, $cardinality)
);
} | [
"public",
"function",
"responded",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"checkResponded",
"(",
")",
")",
"{",
"return",
"$",
"resul... | Throws an exception unless this spy responded.
@return EventCollection|null The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"this",
"spy",
"responded",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L548-L559 |
41,957 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.checkCompleted | public function checkCompleted(): ?EventCollection
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
foreach ($calls as $call) {
if ($endEvent = $call->endEvent()) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkCompleted(): ?EventCollection
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
foreach ($calls as $call) {
if ($endEvent = $call->endEvent()) {
$matchingEvents[] = $endEvent;
++$matchCount;
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkCompleted",
"(",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"calls",
"=",
"$",
"this",
"->",
"spy",
"->",
"allCalls",
"(",
")",
";",
"$",
"match... | Checks if this spy completed.
@return EventCollection|null The result. | [
"Checks",
"if",
"this",
"spy",
"completed",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L566-L587 |
41,958 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.checkReturned | public function checkReturned($value = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
if (0 === func_num_args()) {
foreach ($calls as $call) {
if (!$responseEvent = $call->responseEvent()) {
continue;
}
list($exception) = $call->response();
if (!$exception) {
$matchingEvents[] = $responseEvent;
++$matchCount;
}
}
} else {
$value = $this->matcherFactory->adapt($value);
foreach ($calls as $call) {
if (!$responseEvent = $call->responseEvent()) {
continue;
}
list($exception, $returnValue) = $call->response();
if (!$exception && $value->matches($returnValue)) {
$matchingEvents[] = $responseEvent;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | php | public function checkReturned($value = null): ?EventCollection
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
if (0 === func_num_args()) {
foreach ($calls as $call) {
if (!$responseEvent = $call->responseEvent()) {
continue;
}
list($exception) = $call->response();
if (!$exception) {
$matchingEvents[] = $responseEvent;
++$matchCount;
}
}
} else {
$value = $this->matcherFactory->adapt($value);
foreach ($calls as $call) {
if (!$responseEvent = $call->responseEvent()) {
continue;
}
list($exception, $returnValue) = $call->response();
if (!$exception && $value->matches($returnValue)) {
$matchingEvents[] = $responseEvent;
++$matchCount;
}
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccess($matchingEvents);
}
return null;
} | [
"public",
"function",
"checkReturned",
"(",
"$",
"value",
"=",
"null",
")",
":",
"?",
"EventCollection",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"calls",
"=",
"$",
"this",
"->",
"spy",
"->",
"allCalls",
... | Checks if this spy returned the supplied value.
@param mixed $value The value.
@return EventCollection|null The result. | [
"Checks",
"if",
"this",
"spy",
"returned",
"the",
"supplied",
"value",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L615-L659 |
41,959 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.checkGenerated | public function checkGenerated(): ?GeneratorVerifier
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
foreach ($calls as $call) {
if (!$call->responseEvent()) {
continue;
}
list(, $returnValue) = $call->response();
if ($returnValue instanceof Generator) {
$matchingEvents[] = $call;
++$matchCount;
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccessFromEventCollection(
$this->generatorVerifierFactory
->create($this->spy, $matchingEvents)
);
}
return null;
} | php | public function checkGenerated(): ?GeneratorVerifier
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
foreach ($calls as $call) {
if (!$call->responseEvent()) {
continue;
}
list(, $returnValue) = $call->response();
if ($returnValue instanceof Generator) {
$matchingEvents[] = $call;
++$matchCount;
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccessFromEventCollection(
$this->generatorVerifierFactory
->create($this->spy, $matchingEvents)
);
}
return null;
} | [
"public",
"function",
"checkGenerated",
"(",
")",
":",
"?",
"GeneratorVerifier",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"calls",
"=",
"$",
"this",
"->",
"spy",
"->",
"allCalls",
"(",
")",
";",
"$",
"mat... | Checks if this spy returned a generator.
@return GeneratorVerifier|null The result. | [
"Checks",
"if",
"this",
"spy",
"returned",
"a",
"generator",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L822-L852 |
41,960 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.generated | public function generated(): ?GeneratorVerifier
{
$cardinality = $this->cardinality;
if ($result = $this->checkGenerated()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderGenerated($this->spy, $cardinality)
);
} | php | public function generated(): ?GeneratorVerifier
{
$cardinality = $this->cardinality;
if ($result = $this->checkGenerated()) {
return $result;
}
return $this->assertionRecorder->createFailure(
$this->assertionRenderer->renderGenerated($this->spy, $cardinality)
);
} | [
"public",
"function",
"generated",
"(",
")",
":",
"?",
"GeneratorVerifier",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"cardinality",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"checkGenerated",
"(",
")",
")",
"{",
"return",
"$",
"res... | Throws an exception unless this spy returned a generator.
@return GeneratorVerifier The result, or null if the assertion recorder does not throw exceptions.
@throws Throwable If the assertion fails, and the assertion recorder throws exceptions. | [
"Throws",
"an",
"exception",
"unless",
"this",
"spy",
"returned",
"a",
"generator",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L860-L871 |
41,961 | eloquent/phony | src/Spy/SpyVerifier.php | SpyVerifier.checkIterated | public function checkIterated(): ?IterableVerifier
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
foreach ($calls as $call) {
if (!$call->responseEvent()) {
continue;
}
list(, $returnValue) = $call->response();
if ($returnValue instanceof Traversable || is_array($returnValue)) {
$matchingEvents[] = $call;
++$matchCount;
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccessFromEventCollection(
$this->iterableVerifierFactory
->create($this->spy, $matchingEvents)
);
}
return null;
} | php | public function checkIterated(): ?IterableVerifier
{
$cardinality = $this->resetCardinality();
$calls = $this->spy->allCalls();
$matchingEvents = [];
$totalCount = count($calls);
$matchCount = 0;
foreach ($calls as $call) {
if (!$call->responseEvent()) {
continue;
}
list(, $returnValue) = $call->response();
if ($returnValue instanceof Traversable || is_array($returnValue)) {
$matchingEvents[] = $call;
++$matchCount;
}
}
if ($cardinality->matches($matchCount, $totalCount)) {
return $this->assertionRecorder->createSuccessFromEventCollection(
$this->iterableVerifierFactory
->create($this->spy, $matchingEvents)
);
}
return null;
} | [
"public",
"function",
"checkIterated",
"(",
")",
":",
"?",
"IterableVerifier",
"{",
"$",
"cardinality",
"=",
"$",
"this",
"->",
"resetCardinality",
"(",
")",
";",
"$",
"calls",
"=",
"$",
"this",
"->",
"spy",
"->",
"allCalls",
"(",
")",
";",
"$",
"match... | Checks if this spy returned an iterable.
@return IterableVerifier|null The result. | [
"Checks",
"if",
"this",
"spy",
"returned",
"an",
"iterable",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifier.php#L878-L908 |
41,962 | eloquent/phony | src/Spy/SpyVerifierFactory.php | SpyVerifierFactory.create | public function create(Spy $spy = null): SpyVerifier
{
if (!$spy) {
$spy = $this->spyFactory->create();
}
return new SpyVerifier(
$spy,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | php | public function create(Spy $spy = null): SpyVerifier
{
if (!$spy) {
$spy = $this->spyFactory->create();
}
return new SpyVerifier(
$spy,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | [
"public",
"function",
"create",
"(",
"Spy",
"$",
"spy",
"=",
"null",
")",
":",
"SpyVerifier",
"{",
"if",
"(",
"!",
"$",
"spy",
")",
"{",
"$",
"spy",
"=",
"$",
"this",
"->",
"spyFactory",
"->",
"create",
"(",
")",
";",
"}",
"return",
"new",
"SpyVe... | Create a new spy verifier.
@param Spy|null $spy The spy, or null to create an anonymous spy.
@return SpyVerifier The newly created spy verifier. | [
"Create",
"a",
"new",
"spy",
"verifier",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifierFactory.php#L89-L105 |
41,963 | eloquent/phony | src/Spy/SpyVerifierFactory.php | SpyVerifierFactory.createFromCallback | public function createFromCallback($callback): SpyVerifier
{
return new SpyVerifier(
$this->spyFactory->create($callback),
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | php | public function createFromCallback($callback): SpyVerifier
{
return new SpyVerifier(
$this->spyFactory->create($callback),
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | [
"public",
"function",
"createFromCallback",
"(",
"$",
"callback",
")",
":",
"SpyVerifier",
"{",
"return",
"new",
"SpyVerifier",
"(",
"$",
"this",
"->",
"spyFactory",
"->",
"create",
"(",
"$",
"callback",
")",
",",
"$",
"this",
"->",
"matcherFactory",
",",
... | Create a new spy verifier for the supplied callback.
@param callable|null $callback The callback, or null to create an anonymous spy.
@return SpyVerifier The newly created spy verifier. | [
"Create",
"a",
"new",
"spy",
"verifier",
"for",
"the",
"supplied",
"callback",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifierFactory.php#L114-L126 |
41,964 | eloquent/phony | src/Spy/SpyVerifierFactory.php | SpyVerifierFactory.createGlobal | public function createGlobal(
string $function,
string $namespace
): SpyVerifier {
if (false !== strpos($function, '\\')) {
throw new InvalidArgumentException(
'Only functions in the global namespace are supported.'
);
}
$namespace = trim($namespace, '\\');
if (!$namespace) {
throw new InvalidArgumentException(
'The supplied namespace must not be empty.'
);
}
$spy = $this->spyFactory->create($function);
$this->functionHookManager->defineFunction($function, $namespace, $spy);
return new SpyVerifier(
$spy,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | php | public function createGlobal(
string $function,
string $namespace
): SpyVerifier {
if (false !== strpos($function, '\\')) {
throw new InvalidArgumentException(
'Only functions in the global namespace are supported.'
);
}
$namespace = trim($namespace, '\\');
if (!$namespace) {
throw new InvalidArgumentException(
'The supplied namespace must not be empty.'
);
}
$spy = $this->spyFactory->create($function);
$this->functionHookManager->defineFunction($function, $namespace, $spy);
return new SpyVerifier(
$spy,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer
);
} | [
"public",
"function",
"createGlobal",
"(",
"string",
"$",
"function",
",",
"string",
"$",
"namespace",
")",
":",
"SpyVerifier",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"function",
",",
"'\\\\'",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentEx... | Create a new spy verifier for a global function and declare it in the
specified namespace.
@param string $function The function name.
@param string $namespace The namespace.
@return SpyVerifier The newly created spy verifier.
@throws InvalidArgumentException If an invalid function name or namespace is specified. | [
"Create",
"a",
"new",
"spy",
"verifier",
"for",
"a",
"global",
"function",
"and",
"declare",
"it",
"in",
"the",
"specified",
"namespace",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/SpyVerifierFactory.php#L138-L169 |
41,965 | eloquent/phony | src/Mock/Handle/InstanceHandle.php | InstanceHandle.constructWith | public function constructWith($arguments = []): self
{
if ($this->callParentConstructorMethod) {
if (!$arguments instanceof Arguments) {
$arguments = new Arguments($arguments);
}
$this->callParentConstructorMethod->invoke($this->mock, $arguments);
}
return $this;
} | php | public function constructWith($arguments = []): self
{
if ($this->callParentConstructorMethod) {
if (!$arguments instanceof Arguments) {
$arguments = new Arguments($arguments);
}
$this->callParentConstructorMethod->invoke($this->mock, $arguments);
}
return $this;
} | [
"public",
"function",
"constructWith",
"(",
"$",
"arguments",
"=",
"[",
"]",
")",
":",
"self",
"{",
"if",
"(",
"$",
"this",
"->",
"callParentConstructorMethod",
")",
"{",
"if",
"(",
"!",
"$",
"arguments",
"instanceof",
"Arguments",
")",
"{",
"$",
"argume... | Call the original constructor.
@param Arguments|array $arguments The arguments.
@return $this This handle. | [
"Call",
"the",
"original",
"constructor",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/InstanceHandle.php#L126-L137 |
41,966 | eloquent/phony | src/Mock/Handle/InstanceHandle.php | InstanceHandle.proxy | public function proxy($object): Handle
{
$reflector = new ReflectionObject($object);
foreach ($reflector->getMethods() as $method) {
if (
$method->isStatic() ||
$method->isPrivate() ||
$method->isConstructor() ||
$method->isDestructor()
) {
continue;
}
$name = $method->getName();
if ($this->class->hasMethod($name)) {
$method->setAccessible(true);
$this->stub($name)->doesWith(
function ($arguments) use ($method, $object) {
return $method->invokeArgs($object, $arguments->all());
},
[],
false,
true,
false
);
}
}
return $this;
} | php | public function proxy($object): Handle
{
$reflector = new ReflectionObject($object);
foreach ($reflector->getMethods() as $method) {
if (
$method->isStatic() ||
$method->isPrivate() ||
$method->isConstructor() ||
$method->isDestructor()
) {
continue;
}
$name = $method->getName();
if ($this->class->hasMethod($name)) {
$method->setAccessible(true);
$this->stub($name)->doesWith(
function ($arguments) use ($method, $object) {
return $method->invokeArgs($object, $arguments->all());
},
[],
false,
true,
false
);
}
}
return $this;
} | [
"public",
"function",
"proxy",
"(",
"$",
"object",
")",
":",
"Handle",
"{",
"$",
"reflector",
"=",
"new",
"ReflectionObject",
"(",
"$",
"object",
")",
";",
"foreach",
"(",
"$",
"reflector",
"->",
"getMethods",
"(",
")",
"as",
"$",
"method",
")",
"{",
... | Use the supplied object as the implementation for all methods of the
mock.
This method may help when partial mocking of a particular implementation
is not possible; as in the case of a final class.
@param object $object The object to use.
@return $this This handle. | [
"Use",
"the",
"supplied",
"object",
"as",
"the",
"implementation",
"for",
"all",
"methods",
"of",
"the",
"mock",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Mock/Handle/InstanceHandle.php#L174-L206 |
41,967 | eloquent/phony | src/Spy/GeneratorSpyFactory.php | GeneratorSpyFactory.create | public function create(Call $call, Generator $generator): Generator
{
$spy = $this->createSpy($call, $generator);
$spy->_phonySubject = $generator;
return $spy;
} | php | public function create(Call $call, Generator $generator): Generator
{
$spy = $this->createSpy($call, $generator);
$spy->_phonySubject = $generator;
return $spy;
} | [
"public",
"function",
"create",
"(",
"Call",
"$",
"call",
",",
"Generator",
"$",
"generator",
")",
":",
"Generator",
"{",
"$",
"spy",
"=",
"$",
"this",
"->",
"createSpy",
"(",
"$",
"call",
",",
"$",
"generator",
")",
";",
"$",
"spy",
"->",
"_phonySub... | Create a new generator spy.
@param Call $call The call from which the generator originated.
@param Generator $generator The generator.
@return Generator The newly created generator spy. | [
"Create",
"a",
"new",
"generator",
"spy",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Spy/GeneratorSpyFactory.php#L49-L55 |
41,968 | eloquent/phony | src/Stub/StubVerifierFactory.php | StubVerifierFactory.create | public function create(Stub $stub = null, $self = null): StubVerifier
{
if (!$stub) {
$stub = $this->stubFactory->create();
}
$verifier = new StubVerifier(
$stub,
$this->spyFactory->create($stub),
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer,
$this->generatorAnswerBuilderFactory
);
if (func_num_args() > 1) {
$verifier->setSelf($self);
} else {
$verifier->setSelf($verifier);
}
return $verifier;
} | php | public function create(Stub $stub = null, $self = null): StubVerifier
{
if (!$stub) {
$stub = $this->stubFactory->create();
}
$verifier = new StubVerifier(
$stub,
$this->spyFactory->create($stub),
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer,
$this->generatorAnswerBuilderFactory
);
if (func_num_args() > 1) {
$verifier->setSelf($self);
} else {
$verifier->setSelf($verifier);
}
return $verifier;
} | [
"public",
"function",
"create",
"(",
"Stub",
"$",
"stub",
"=",
"null",
",",
"$",
"self",
"=",
"null",
")",
":",
"StubVerifier",
"{",
"if",
"(",
"!",
"$",
"stub",
")",
"{",
"$",
"stub",
"=",
"$",
"this",
"->",
"stubFactory",
"->",
"create",
"(",
"... | Create a new stub verifier.
If the "self" value is omitted, it will be set to the verifier itself.
@param Stub|null $stub The stub, or null to create an anonymous stub.
@param mixed $self The "self" value.
@return StubVerifier The newly created stub verifier. | [
"Create",
"a",
"new",
"stub",
"verifier",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifierFactory.php#L103-L129 |
41,969 | eloquent/phony | src/Stub/StubVerifierFactory.php | StubVerifierFactory.createFromCallback | public function createFromCallback($callback): StubVerifier
{
$stub = $this->stubFactory->create($callback);
$verifier = new StubVerifier(
$stub,
$this->spyFactory->create($stub),
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer,
$this->generatorAnswerBuilderFactory
);
$verifier->setSelf($verifier);
return $verifier;
} | php | public function createFromCallback($callback): StubVerifier
{
$stub = $this->stubFactory->create($callback);
$verifier = new StubVerifier(
$stub,
$this->spyFactory->create($stub),
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer,
$this->generatorAnswerBuilderFactory
);
$verifier->setSelf($verifier);
return $verifier;
} | [
"public",
"function",
"createFromCallback",
"(",
"$",
"callback",
")",
":",
"StubVerifier",
"{",
"$",
"stub",
"=",
"$",
"this",
"->",
"stubFactory",
"->",
"create",
"(",
"$",
"callback",
")",
";",
"$",
"verifier",
"=",
"new",
"StubVerifier",
"(",
"$",
"s... | Create a new stub verifier for the supplied callback.
@param callable|null $callback The callback, or null to create an anonymous stub.
@return StubVerifier The newly created stub verifier. | [
"Create",
"a",
"new",
"stub",
"verifier",
"for",
"the",
"supplied",
"callback",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifierFactory.php#L138-L157 |
41,970 | eloquent/phony | src/Stub/StubVerifierFactory.php | StubVerifierFactory.createGlobal | public function createGlobal(
string $function,
string $namespace
): StubVerifier {
if (false !== strpos($function, '\\')) {
throw new InvalidArgumentException(
'Only functions in the global namespace are supported.'
);
}
$namespace = trim($namespace, '\\');
if (!$namespace) {
throw new InvalidArgumentException(
'The supplied namespace must not be empty.'
);
}
$stub = $this->stubFactory->create($function);
$spy = $this->spyFactory->create($stub);
$this->functionHookManager->defineFunction($function, $namespace, $spy);
$verifier = new StubVerifier(
$stub,
$spy,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer,
$this->generatorAnswerBuilderFactory
);
$verifier->setSelf($verifier);
return $verifier;
} | php | public function createGlobal(
string $function,
string $namespace
): StubVerifier {
if (false !== strpos($function, '\\')) {
throw new InvalidArgumentException(
'Only functions in the global namespace are supported.'
);
}
$namespace = trim($namespace, '\\');
if (!$namespace) {
throw new InvalidArgumentException(
'The supplied namespace must not be empty.'
);
}
$stub = $this->stubFactory->create($function);
$spy = $this->spyFactory->create($stub);
$this->functionHookManager->defineFunction($function, $namespace, $spy);
$verifier = new StubVerifier(
$stub,
$spy,
$this->matcherFactory,
$this->matcherVerifier,
$this->generatorVerifierFactory,
$this->iterableVerifierFactory,
$this->callVerifierFactory,
$this->assertionRecorder,
$this->assertionRenderer,
$this->generatorAnswerBuilderFactory
);
$verifier->setSelf($verifier);
return $verifier;
} | [
"public",
"function",
"createGlobal",
"(",
"string",
"$",
"function",
",",
"string",
"$",
"namespace",
")",
":",
"StubVerifier",
"{",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"function",
",",
"'\\\\'",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentE... | Create a new stub verifier for a global function and declare it in the
specified namespace.
@param string $function The function name.
@param string $namespace The namespace.
@return StubVerifier The newly created stub verifier.
@throws InvalidArgumentException If an invalid function name or namespace is specified. | [
"Create",
"a",
"new",
"stub",
"verifier",
"for",
"a",
"global",
"function",
"and",
"declare",
"it",
"in",
"the",
"specified",
"namespace",
"."
] | 54ac8a937079da0d818d82aaf5edd61501c48f2c | https://github.com/eloquent/phony/blob/54ac8a937079da0d818d82aaf5edd61501c48f2c/src/Stub/StubVerifierFactory.php#L169-L206 |
41,971 | scriptotek/php-marc | src/Fields/Field.php | Field.toString | protected function toString($codes, $options = [])
{
$glue = isset($options['glue']) ? $options['glue'] : static::$glue;
return $this->clean(implode($glue, $this->getSubfieldValues($codes)), $options);
} | php | protected function toString($codes, $options = [])
{
$glue = isset($options['glue']) ? $options['glue'] : static::$glue;
return $this->clean(implode($glue, $this->getSubfieldValues($codes)), $options);
} | [
"protected",
"function",
"toString",
"(",
"$",
"codes",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"glue",
"=",
"isset",
"(",
"$",
"options",
"[",
"'glue'",
"]",
")",
"?",
"$",
"options",
"[",
"'glue'",
"]",
":",
"static",
"::",
"$",
"glu... | Return concatenated string of the given subfields.
@param string[] $codes
@param array $options
@return string | [
"Return",
"concatenated",
"string",
"of",
"the",
"given",
"subfields",
"."
] | 79086165dfce9b9d2f490d38e9f50f70fef5641f | https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Fields/Field.php#L95-L99 |
41,972 | scriptotek/php-marc | src/Fields/Field.php | Field.asLineMarc | public function asLineMarc($sep = '$', $blank = ' ')
{
if ($this->field->isEmpty()) {
return null;
}
$subfields = [];
foreach ($this->field->getSubfields() as $sf) {
$subfields[] = $sep . $sf->getCode() . ' ' . $sf->getData();
}
$tag = $this->field->getTag();
$ind1 = $this->field->getIndicator(1);
$ind2 = $this->field->getIndicator(2);
if ($ind1 == ' ') {
$ind1 = $blank;
}
if ($ind2 == ' ') {
$ind2 = $blank;
}
return "${tag} ${ind1}${ind2} " . implode(' ', $subfields);
} | php | public function asLineMarc($sep = '$', $blank = ' ')
{
if ($this->field->isEmpty()) {
return null;
}
$subfields = [];
foreach ($this->field->getSubfields() as $sf) {
$subfields[] = $sep . $sf->getCode() . ' ' . $sf->getData();
}
$tag = $this->field->getTag();
$ind1 = $this->field->getIndicator(1);
$ind2 = $this->field->getIndicator(2);
if ($ind1 == ' ') {
$ind1 = $blank;
}
if ($ind2 == ' ') {
$ind2 = $blank;
}
return "${tag} ${ind1}${ind2} " . implode(' ', $subfields);
} | [
"public",
"function",
"asLineMarc",
"(",
"$",
"sep",
"=",
"'$'",
",",
"$",
"blank",
"=",
"' '",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"field",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"subfields",
"=",
"[",
"]",
"... | Return a line MARC representation of the field. If the field is deleted,
null is returned.
@param string $sep Subfield separator character, defaults to '$'
@param string $blank Blank indicator character, defaults to ' '
@return string|null. | [
"Return",
"a",
"line",
"MARC",
"representation",
"of",
"the",
"field",
".",
"If",
"the",
"field",
"is",
"deleted",
"null",
"is",
"returned",
"."
] | 79086165dfce9b9d2f490d38e9f50f70fef5641f | https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Fields/Field.php#L109-L129 |
41,973 | scriptotek/php-marc | src/BibliographicRecord.php | BibliographicRecord.getCreators | public function getCreators($tag = null)
{
$tag = is_null($tag) ? [] : (is_array($tag) ? $tag : [$tag]);
return array_values(array_filter(Person::get($this), function (Person $person) use ($tag) {
return empty($tag) || in_array($person->getType(), $tag);
}));
} | php | public function getCreators($tag = null)
{
$tag = is_null($tag) ? [] : (is_array($tag) ? $tag : [$tag]);
return array_values(array_filter(Person::get($this), function (Person $person) use ($tag) {
return empty($tag) || in_array($person->getType(), $tag);
}));
} | [
"public",
"function",
"getCreators",
"(",
"$",
"tag",
"=",
"null",
")",
"{",
"$",
"tag",
"=",
"is_null",
"(",
"$",
"tag",
")",
"?",
"[",
"]",
":",
"(",
"is_array",
"(",
"$",
"tag",
")",
"?",
"$",
"tag",
":",
"[",
"$",
"tag",
"]",
")",
";",
... | Get an array of the 100 and 700 fields as `Person` objects, optionally
filtered by tag.
@param string|string[] $tag
@return Person[] | [
"Get",
"an",
"array",
"of",
"the",
"100",
"and",
"700",
"fields",
"as",
"Person",
"objects",
"optionally",
"filtered",
"by",
"tag",
"."
] | 79086165dfce9b9d2f490d38e9f50f70fef5641f | https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/BibliographicRecord.php#L176-L183 |
41,974 | scriptotek/php-marc | src/Collection.php | Collection.getRecordType | public static function getRecordType(File_MARC_Record $record)
{
$leader = $record->getLeader();
$recordType = substr($leader, 6, 1);
switch ($recordType) {
case 'a': // Language material
case 'c': // Notated music
case 'd': // Manuscript notated music
case 'e': // Cartographic material
case 'f': // Manuscript cartographic material
case 'g': // Projected medium
case 'i': // Nonmusical sound recording
case 'j': // Musical sound recording
case 'k': // Two-dimensional nonprojectable graphic
case 'm': // Computer file
case 'o': // Kit
case 'p': // Mixed materials
case 'r': // Three-dimensional artifact or naturally occurring object
case 't': // Manuscript language material
return Marc21::BIBLIOGRAPHIC;
case 'z':
return Marc21::AUTHORITY;
case 'u': // Unknown
case 'v': // Multipart item holdings
case 'x': // Single-part item holdings
case 'y': // Serial item holdings
return Marc21::HOLDINGS;
default:
throw new UnknownRecordType();
}
} | php | public static function getRecordType(File_MARC_Record $record)
{
$leader = $record->getLeader();
$recordType = substr($leader, 6, 1);
switch ($recordType) {
case 'a': // Language material
case 'c': // Notated music
case 'd': // Manuscript notated music
case 'e': // Cartographic material
case 'f': // Manuscript cartographic material
case 'g': // Projected medium
case 'i': // Nonmusical sound recording
case 'j': // Musical sound recording
case 'k': // Two-dimensional nonprojectable graphic
case 'm': // Computer file
case 'o': // Kit
case 'p': // Mixed materials
case 'r': // Three-dimensional artifact or naturally occurring object
case 't': // Manuscript language material
return Marc21::BIBLIOGRAPHIC;
case 'z':
return Marc21::AUTHORITY;
case 'u': // Unknown
case 'v': // Multipart item holdings
case 'x': // Single-part item holdings
case 'y': // Serial item holdings
return Marc21::HOLDINGS;
default:
throw new UnknownRecordType();
}
} | [
"public",
"static",
"function",
"getRecordType",
"(",
"File_MARC_Record",
"$",
"record",
")",
"{",
"$",
"leader",
"=",
"$",
"record",
"->",
"getLeader",
"(",
")",
";",
"$",
"recordType",
"=",
"substr",
"(",
"$",
"leader",
",",
"6",
",",
"1",
")",
";",
... | Determines if a record is a bibliographic, holdings or authority record.
@param File_MARC_Record $record
@return string | [
"Determines",
"if",
"a",
"record",
"is",
"a",
"bibliographic",
"holdings",
"or",
"authority",
"record",
"."
] | 79086165dfce9b9d2f490d38e9f50f70fef5641f | https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Collection.php#L59-L90 |
41,975 | scriptotek/php-marc | src/Collection.php | Collection.recordFactory | public function recordFactory(File_MARC_Record $record)
{
try {
$recordType = self::getRecordType($record);
} catch (UnknownRecordType $e) {
return new Record($record);
}
switch ($recordType) {
case Marc21::BIBLIOGRAPHIC:
return new BibliographicRecord($record);
case Marc21::HOLDINGS:
return new HoldingsRecord($record);
case Marc21::AUTHORITY:
return new AuthorityRecord($record);
}
} | php | public function recordFactory(File_MARC_Record $record)
{
try {
$recordType = self::getRecordType($record);
} catch (UnknownRecordType $e) {
return new Record($record);
}
switch ($recordType) {
case Marc21::BIBLIOGRAPHIC:
return new BibliographicRecord($record);
case Marc21::HOLDINGS:
return new HoldingsRecord($record);
case Marc21::AUTHORITY:
return new AuthorityRecord($record);
}
} | [
"public",
"function",
"recordFactory",
"(",
"File_MARC_Record",
"$",
"record",
")",
"{",
"try",
"{",
"$",
"recordType",
"=",
"self",
"::",
"getRecordType",
"(",
"$",
"record",
")",
";",
"}",
"catch",
"(",
"UnknownRecordType",
"$",
"e",
")",
"{",
"return",
... | Creates a Record object from a File_MARC_Record object.
@param File_MARC_Record $record
@return AuthorityRecord|BibliographicRecord|HoldingsRecord | [
"Creates",
"a",
"Record",
"object",
"from",
"a",
"File_MARC_Record",
"object",
"."
] | 79086165dfce9b9d2f490d38e9f50f70fef5641f | https://github.com/scriptotek/php-marc/blob/79086165dfce9b9d2f490d38e9f50f70fef5641f/src/Collection.php#L108-L125 |
41,976 | wayfair/hypernova-php | src/Renderer.php | Renderer.addJob | public function addJob($id, $job)
{
if (is_array($job)) {
$job = Job::fromArray($job);
}
$this->incomingJobs[$id] = $job;
} | php | public function addJob($id, $job)
{
if (is_array($job)) {
$job = Job::fromArray($job);
}
$this->incomingJobs[$id] = $job;
} | [
"public",
"function",
"addJob",
"(",
"$",
"id",
",",
"$",
"job",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"job",
")",
")",
"{",
"$",
"job",
"=",
"Job",
"::",
"fromArray",
"(",
"$",
"job",
")",
";",
"}",
"$",
"this",
"->",
"incomingJobs",
"[",... | Add a job
@param string $id
@param \WF\Hypernova\Job|array $job Job to add, { [view]: { name: String, data: ReactProps } } | [
"Add",
"a",
"job"
] | 0b352762eab4a78bf27a8a1b25405d5cf4281460 | https://github.com/wayfair/hypernova-php/blob/0b352762eab4a78bf27a8a1b25405d5cf4281460/src/Renderer.php#L73-L79 |
41,977 | wayfair/hypernova-php | src/Renderer.php | Renderer.render | public function render()
{
$jobs = $this->createJobs();
try {
list($shouldSendRequest, $jobs) = $this->prepareRequest($jobs);
if (!$shouldSendRequest) {
return $this->fallback(null, $jobs);
}
} catch (\Exception $e) {
return $this->fallback($e, $jobs);
}
try {
return $this->makeRequest($jobs);
} catch (\Exception $e) {
return $this->fallback($e, $jobs);
}
} | php | public function render()
{
$jobs = $this->createJobs();
try {
list($shouldSendRequest, $jobs) = $this->prepareRequest($jobs);
if (!$shouldSendRequest) {
return $this->fallback(null, $jobs);
}
} catch (\Exception $e) {
return $this->fallback($e, $jobs);
}
try {
return $this->makeRequest($jobs);
} catch (\Exception $e) {
return $this->fallback($e, $jobs);
}
} | [
"public",
"function",
"render",
"(",
")",
"{",
"$",
"jobs",
"=",
"$",
"this",
"->",
"createJobs",
"(",
")",
";",
"try",
"{",
"list",
"(",
"$",
"shouldSendRequest",
",",
"$",
"jobs",
")",
"=",
"$",
"this",
"->",
"prepareRequest",
"(",
"$",
"jobs",
"... | Do the things.
@return \WF\Hypernova\Response | [
"Do",
"the",
"things",
"."
] | 0b352762eab4a78bf27a8a1b25405d5cf4281460 | https://github.com/wayfair/hypernova-php/blob/0b352762eab4a78bf27a8a1b25405d5cf4281460/src/Renderer.php#L86-L103 |
41,978 | drupal-code-builder/drupal-code-builder | Task/ReportHookPresets.php | ReportHookPresets.loadPresetsFile | protected function loadPresetsFile($filename) {
$pieces = array('templates', $this->environment->getCoreMajorVersion(), $filename);
$path = $this->environment->getPath(implode('/', $pieces));
if (!file_exists($path)) {
throw new \Exception(strtr("Unable to find template at !path.", array(
'!path' => htmlspecialchars($path, ENT_QUOTES, 'UTF-8'),
)));
}
$template_file = file_get_contents($path);
return $template_file;
} | php | protected function loadPresetsFile($filename) {
$pieces = array('templates', $this->environment->getCoreMajorVersion(), $filename);
$path = $this->environment->getPath(implode('/', $pieces));
if (!file_exists($path)) {
throw new \Exception(strtr("Unable to find template at !path.", array(
'!path' => htmlspecialchars($path, ENT_QUOTES, 'UTF-8'),
)));
}
$template_file = file_get_contents($path);
return $template_file;
} | [
"protected",
"function",
"loadPresetsFile",
"(",
"$",
"filename",
")",
"{",
"$",
"pieces",
"=",
"array",
"(",
"'templates'",
",",
"$",
"this",
"->",
"environment",
"->",
"getCoreMajorVersion",
"(",
")",
",",
"$",
"filename",
")",
";",
"$",
"path",
"=",
"... | Returns the contents of a template file.
TODO: this will eventually return either the user version or the module version.
TODO: IS THIS IN THE RIGHT FILE???
@param $filename
The filename of the template file to read.
@return
The contents of the file, or NULL if the file is not found.
@throws \Exception
Throws an exception if the file can't be found. | [
"Returns",
"the",
"contents",
"of",
"a",
"template",
"file",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookPresets.php#L35-L47 |
41,979 | drupal-code-builder/drupal-code-builder | Task/ReportHookPresets.php | ReportHookPresets.getHookPresets | function getHookPresets() {
// TODO: read user file preferentially.
$presets_template = $this->loadPresetsFile('hook_groups.template');
$hook_presets = json_decode(preg_replace("@//.*@", '', $presets_template), TRUE);
if (is_null($hook_presets)) {
// @TODO: do something here to say its gone wrong. Throw Exception?
drupal_set_message(t('Problem reading json file.'), 'error');
}
return $hook_presets;
} | php | function getHookPresets() {
// TODO: read user file preferentially.
$presets_template = $this->loadPresetsFile('hook_groups.template');
$hook_presets = json_decode(preg_replace("@//.*@", '', $presets_template), TRUE);
if (is_null($hook_presets)) {
// @TODO: do something here to say its gone wrong. Throw Exception?
drupal_set_message(t('Problem reading json file.'), 'error');
}
return $hook_presets;
} | [
"function",
"getHookPresets",
"(",
")",
"{",
"// TODO: read user file preferentially.",
"$",
"presets_template",
"=",
"$",
"this",
"->",
"loadPresetsFile",
"(",
"'hook_groups.template'",
")",
";",
"$",
"hook_presets",
"=",
"json_decode",
"(",
"preg_replace",
"(",
"\"@... | Get the definition of hook presets.
A preset is a collection of hooks with a machine name and a descriptive
label. Presets allow quick selection of hooks that are commonly used
together, eg those used to define a node type, or blocks.
@return
An array keyed by preset name, whose values are arrays of the form:
'label': The label shown to the user.
'hooks': A flat array of full hook names, eg 'hook_menu'. | [
"Get",
"the",
"definition",
"of",
"hook",
"presets",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookPresets.php#L61-L70 |
41,980 | drupal-code-builder/drupal-code-builder | Generator/BaseGenerator.php | BaseGenerator.getComponentDataValue | public function getComponentDataValue($name) {
if (!isset($this->component_data[$name])) {
throw new \Exception(strtr("Property @name not found in data for @type.", [
'@name' => $name,
'@type' => get_class($this),
]));
}
return $this->component_data[$name];
} | php | public function getComponentDataValue($name) {
if (!isset($this->component_data[$name])) {
throw new \Exception(strtr("Property @name not found in data for @type.", [
'@name' => $name,
'@type' => get_class($this),
]));
}
return $this->component_data[$name];
} | [
"public",
"function",
"getComponentDataValue",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"component_data",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"strtr",
"(",
"\"Property @name no... | Get the value of a component property.
@param string $name
The property name.
@return mixed
The value. | [
"Get",
"the",
"value",
"of",
"a",
"component",
"property",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/BaseGenerator.php#L312-L321 |
41,981 | drupal-code-builder/drupal-code-builder | Generator/BaseGenerator.php | BaseGenerator.mergeComponentData | public function mergeComponentData($additional_component_data) {
$differences_merged = FALSE;
// Get the property info for just this component: we don't care about
// going into compound properties.
$component_property_info = static::componentDataDefinition();
// Only merge array properties.
foreach ($component_property_info as $property_name => $property_info) {
// Skip this property if there's nothing here.
if (!isset($this->component_data[$property_name]) && !isset($additional_component_data[$property_name])) {
continue;
}
// We're getting the component data direct, so it won't have default
// attributes filled in: 'format' might not be set.
if (!isset($property_info['format']) || $property_info['format'] != 'array') {
// Don't merge this property, but check that we're not throwing away
// data from the additional data.
assert($this->component_data[$property_name] == $additional_component_data[$property_name],
"Attempted to discard request for new component, but failed on property $property_name with existing data "
. print_r($this->component_data, TRUE)
. " and new data "
. print_r($additional_component_data, TRUE)
);
continue;
}
if ($this->component_data[$property_name] != $additional_component_data[$property_name]) {
$differences_merged = TRUE;
$this->component_data[$property_name] = array_merge_recursive($this->component_data[$property_name], $additional_component_data[$property_name]);
}
}
return $differences_merged;
} | php | public function mergeComponentData($additional_component_data) {
$differences_merged = FALSE;
// Get the property info for just this component: we don't care about
// going into compound properties.
$component_property_info = static::componentDataDefinition();
// Only merge array properties.
foreach ($component_property_info as $property_name => $property_info) {
// Skip this property if there's nothing here.
if (!isset($this->component_data[$property_name]) && !isset($additional_component_data[$property_name])) {
continue;
}
// We're getting the component data direct, so it won't have default
// attributes filled in: 'format' might not be set.
if (!isset($property_info['format']) || $property_info['format'] != 'array') {
// Don't merge this property, but check that we're not throwing away
// data from the additional data.
assert($this->component_data[$property_name] == $additional_component_data[$property_name],
"Attempted to discard request for new component, but failed on property $property_name with existing data "
. print_r($this->component_data, TRUE)
. " and new data "
. print_r($additional_component_data, TRUE)
);
continue;
}
if ($this->component_data[$property_name] != $additional_component_data[$property_name]) {
$differences_merged = TRUE;
$this->component_data[$property_name] = array_merge_recursive($this->component_data[$property_name], $additional_component_data[$property_name]);
}
}
return $differences_merged;
} | [
"public",
"function",
"mergeComponentData",
"(",
"$",
"additional_component_data",
")",
"{",
"$",
"differences_merged",
"=",
"FALSE",
";",
"// Get the property info for just this component: we don't care about",
"// going into compound properties.",
"$",
"component_property_info",
... | Merge data from additional requests of a component.
@param array $additional_component_data
The array of new component data to merge in. This has the same format as
the parameter to __construct().
@return bool
Boolean indicating whether any data needed to be merged: TRUE if so,
FALSE if nothing was merged because all values were the same. | [
"Merge",
"data",
"from",
"additional",
"requests",
"of",
"a",
"component",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/BaseGenerator.php#L358-L395 |
41,982 | drupal-code-builder/drupal-code-builder | Generator/BaseGenerator.php | BaseGenerator.filterComponentContentsForRole | protected function filterComponentContentsForRole($contents, $role) {
$return = [];
foreach ($contents as $key => $item) {
if ($item['role'] == $role) {
$return[$key] = $item['content'];
}
}
return $return;
} | php | protected function filterComponentContentsForRole($contents, $role) {
$return = [];
foreach ($contents as $key => $item) {
if ($item['role'] == $role) {
$return[$key] = $item['content'];
}
}
return $return;
} | [
"protected",
"function",
"filterComponentContentsForRole",
"(",
"$",
"contents",
",",
"$",
"role",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contents",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"[... | Filters an array of child contents by role.
Helper for buildComponentContents().
@param $contents
The array of contents as returned by an implementation of
buildComponentContents().
@param $role
A role name, as used in the 'role' property of the $contents array.
@return
An array of the 'content' data of the given array items that matched the
role, keyed by the same key as the the given array item. | [
"Filters",
"an",
"array",
"of",
"child",
"contents",
"by",
"role",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/BaseGenerator.php#L512-L520 |
41,983 | drupal-code-builder/drupal-code-builder | Generator/Hooks.php | Hooks.parseTemplate | function parseTemplate($file) {
$data = array();
// Captures a template name and body from a template file.
$pattern = '#== START (.*?) ==(.*?)== END ==#ms';
preg_match_all($pattern, $file, $matches);
$count = count($matches[0]);
for ($i = 0; $i < $count; $i++) {
$data[$matches[1][$i]] = array(
#'title' => $matches[1][$i],
'template' => $matches[2][$i]
);
/*
$hook_custom_declarations[] = array(
'title' => $matches[1][$i],
'data' => $matches[2][$i]
);
*/
}
return $data;
} | php | function parseTemplate($file) {
$data = array();
// Captures a template name and body from a template file.
$pattern = '#== START (.*?) ==(.*?)== END ==#ms';
preg_match_all($pattern, $file, $matches);
$count = count($matches[0]);
for ($i = 0; $i < $count; $i++) {
$data[$matches[1][$i]] = array(
#'title' => $matches[1][$i],
'template' => $matches[2][$i]
);
/*
$hook_custom_declarations[] = array(
'title' => $matches[1][$i],
'data' => $matches[2][$i]
);
*/
}
return $data;
} | [
"function",
"parseTemplate",
"(",
"$",
"file",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"// Captures a template name and body from a template file.",
"$",
"pattern",
"=",
"'#== START (.*?) ==(.*?)== END ==#ms'",
";",
"preg_match_all",
"(",
"$",
"pattern",
"... | Parse a drupal_code_builder template file.
Template files are composed of several sections in the form of:
== START [title of template section] ==
[the body of the template section]
== END ==
@param string $file
The template file to parse
@return Array
Return array keyed by hook name, whose values are of the form:
array('template' => TEMPLATE BODY) | [
"Parse",
"a",
"drupal_code_builder",
"template",
"file",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/Hooks.php#L375-L395 |
41,984 | drupal-code-builder/drupal-code-builder | Task/ReportHookData.php | ReportHookData.listHookData | function listHookData() {
// We may come here several times, so cache this.
if (!empty($this->hook_data)) {
return $this->hook_data;
}
$this->hook_data = $this->environment->getStorage()->retrieve('hooks');
return $this->hook_data;
} | php | function listHookData() {
// We may come here several times, so cache this.
if (!empty($this->hook_data)) {
return $this->hook_data;
}
$this->hook_data = $this->environment->getStorage()->retrieve('hooks');
return $this->hook_data;
} | [
"function",
"listHookData",
"(",
")",
"{",
"// We may come here several times, so cache this.",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"hook_data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"hook_data",
";",
"}",
"$",
"this",
"->",
"hook_data",
"... | Get the list of hook data.
@return
The processed hook data. | [
"Get",
"the",
"list",
"of",
"hook",
"data",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L35-L43 |
41,985 | drupal-code-builder/drupal-code-builder | Task/ReportHookData.php | ReportHookData.listHookNames | function listHookNames($style = 'full') {
$data = $this->getHookDeclarations();
$names = array_keys($data);
if ($style == 'short') {
foreach ($names as $key => $hook_name) {
$names[$key] = str_replace('hook_', '', $hook_name);
}
}
return $names;
} | php | function listHookNames($style = 'full') {
$data = $this->getHookDeclarations();
$names = array_keys($data);
if ($style == 'short') {
foreach ($names as $key => $hook_name) {
$names[$key] = str_replace('hook_', '', $hook_name);
}
}
return $names;
} | [
"function",
"listHookNames",
"(",
"$",
"style",
"=",
"'full'",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getHookDeclarations",
"(",
")",
";",
"$",
"names",
"=",
"array_keys",
"(",
"$",
"data",
")",
";",
"if",
"(",
"$",
"style",
"==",
"'short'",... | Get just hook names.
@param $style
Whether to return hook names as just 'init' or 'hook_init'. One of:
- 'short': Return short names, i.e., 'init'.
- 'full': Return full hook names, i.e., 'hook_init'.
@return
A flat array of strings. | [
"Get",
"just",
"hook",
"names",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L56-L67 |
41,986 | drupal-code-builder/drupal-code-builder | Task/ReportHookData.php | ReportHookData.listHookNamesOptions | function listHookNamesOptions() {
$data = $this->getHookDeclarations();
$return = array();
foreach ($data as $hook_name => $hook_info) {
$return[$hook_name] = $hook_info['description'];
}
return $return;
} | php | function listHookNamesOptions() {
$data = $this->getHookDeclarations();
$return = array();
foreach ($data as $hook_name => $hook_info) {
$return[$hook_name] = $hook_info['description'];
}
return $return;
} | [
"function",
"listHookNamesOptions",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getHookDeclarations",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"hook_name",
"=>",
"$",
"hook_info",
")",
... | Get hooks as a list of options.
@return
An array of hooks as options suitable for FormAPI, where each key is a
full hook name, and each value is a description. | [
"Get",
"hooks",
"as",
"a",
"list",
"of",
"options",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L76-L85 |
41,987 | drupal-code-builder/drupal-code-builder | Task/ReportHookData.php | ReportHookData.listHookOptionsStructured | public function listHookOptionsStructured() {
$data = $this->getHookDeclarations();
$return = array();
foreach ($data as $hook_name => $hook_info) {
$return[$hook_info['group']][$hook_name] = array(
'name' => $hook_info['name'],
'description' => $hook_info['description'],
'type' => $hook_info['type'],
'core' => $hook_info['core'],
);
}
return $return;
} | php | public function listHookOptionsStructured() {
$data = $this->getHookDeclarations();
$return = array();
foreach ($data as $hook_name => $hook_info) {
$return[$hook_info['group']][$hook_name] = array(
'name' => $hook_info['name'],
'description' => $hook_info['description'],
'type' => $hook_info['type'],
'core' => $hook_info['core'],
);
}
return $return;
} | [
"public",
"function",
"listHookOptionsStructured",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"getHookDeclarations",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"hook_name",
"=>",
"$",
"ho... | Get hooks as a grouped list with data about each item.
@return
An array keyed by hook group, whose items are in turn arrays keyed by
hook name standardized to lowercase, and whose items in turn are arrays
with the following properties:
- 'name': The hook name in the original case.
- 'type' One of 'hook' or 'callback'.
- 'description' The first line from the hook definition's docblock. | [
"Get",
"hooks",
"as",
"a",
"grouped",
"list",
"with",
"data",
"about",
"each",
"item",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L98-L112 |
41,988 | drupal-code-builder/drupal-code-builder | Task/ReportHookData.php | ReportHookData.getHookDeclarations | function getHookDeclarations() {
$data = $this->listHookData();
$return = array();
foreach ($data as $group => $hooks) {
foreach ($hooks as $key => $hook) {
// Standardize to lowercase.
$hook_name = strtolower($hook['name']);
$return[$hook_name] = $hook;
}
}
return $return;
} | php | function getHookDeclarations() {
$data = $this->listHookData();
$return = array();
foreach ($data as $group => $hooks) {
foreach ($hooks as $key => $hook) {
// Standardize to lowercase.
$hook_name = strtolower($hook['name']);
$return[$hook_name] = $hook;
}
}
return $return;
} | [
"function",
"getHookDeclarations",
"(",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"listHookData",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"group",
"=>",
"$",
"hooks",
")",
"{",
"foreac... | Get stored hook declarations, keyed by hook name, with destination.
@return
An array of hook information, keyed by the full name of the hook
standardized to lower case.
Each item has the keys:
- 'type': One of 'hook' or 'callback'.
- 'name': The full name of the hook in the original case,
eg 'hook_form_FORM_ID_alter'.
- 'definition': The full function declaration.
- 'description': The first line of the hook docblock.
- 'destination': The file this hook should be placed in, as a module file
pattern such as '%module.module'.
- 'dependencies': TODO!
- 'group': Erm write this later.
- 'file_path': The absolute path of the file this definition was taken
from.
- 'body': The hook function body, taken from the API file. | [
"Get",
"stored",
"hook",
"declarations",
"keyed",
"by",
"hook",
"name",
"with",
"destination",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/ReportHookData.php#L134-L148 |
41,989 | drupal-code-builder/drupal-code-builder | Utility/InsertArray.php | InsertArray.insert | protected static function insert(&$array, $key, $insert_array, $before) {
if (!isset($array[$key])) {
throw new \Exception("The array does not have the key $key.");
}
if ($before) {
$offset = 0;
}
else {
$offset = 1;
}
$pos = array_search($key, array_keys($array));
$pos += $offset;
$array_before = array_slice($array, 0, $pos);
$array_after = array_slice($array, $pos);
$array = array_merge(
$array_before,
$insert_array,
$array_after
);
} | php | protected static function insert(&$array, $key, $insert_array, $before) {
if (!isset($array[$key])) {
throw new \Exception("The array does not have the key $key.");
}
if ($before) {
$offset = 0;
}
else {
$offset = 1;
}
$pos = array_search($key, array_keys($array));
$pos += $offset;
$array_before = array_slice($array, 0, $pos);
$array_after = array_slice($array, $pos);
$array = array_merge(
$array_before,
$insert_array,
$array_after
);
} | [
"protected",
"static",
"function",
"insert",
"(",
"&",
"$",
"array",
",",
"$",
"key",
",",
"$",
"insert_array",
",",
"$",
"before",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"array",
"[",
"$",
"key",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
... | Inserts values into an array before or after a given key.
Helper for insertBefore() and insertAfter().
Values from $insert_array are inserted into $array either before or after
$key.
@param array $array
The array to insert into, passed by reference and altered in place.
@param mixed $key
The key of $array to insert before or after.
@param array $insert_array
An array whose values should be inserted.
@param bool $before
If TRUE, insert before the given key; if FALSE, insert after it.
@throws \Exception
Throws an exception if the array does not have the key $key. | [
"Inserts",
"values",
"into",
"an",
"array",
"before",
"or",
"after",
"a",
"given",
"key",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Utility/InsertArray.php#L73-L96 |
41,990 | drupal-code-builder/drupal-code-builder | Task/Collect/ContainerBuilderGetter.php | ContainerBuilderGetter.getContainerBuilder | public function getContainerBuilder() {
if (!isset($this->containerBuilder)) {
// Get the kernel, and hack it to get a compiled container.
// We need this rather than the normal cached container, as that doesn't
// allow us to get the full service definitions.
$kernel = \Drupal::service('kernel');
$kernel_R = new \ReflectionClass($kernel);
$compileContainer_R = $kernel_R->getMethod('compileContainer');
$compileContainer_R->setAccessible(TRUE);
$this->containerBuilder = $compileContainer_R->invoke($kernel);
}
return $this->containerBuilder;
} | php | public function getContainerBuilder() {
if (!isset($this->containerBuilder)) {
// Get the kernel, and hack it to get a compiled container.
// We need this rather than the normal cached container, as that doesn't
// allow us to get the full service definitions.
$kernel = \Drupal::service('kernel');
$kernel_R = new \ReflectionClass($kernel);
$compileContainer_R = $kernel_R->getMethod('compileContainer');
$compileContainer_R->setAccessible(TRUE);
$this->containerBuilder = $compileContainer_R->invoke($kernel);
}
return $this->containerBuilder;
} | [
"public",
"function",
"getContainerBuilder",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"containerBuilder",
")",
")",
"{",
"// Get the kernel, and hack it to get a compiled container.",
"// We need this rather than the normal cached container, as that doesn... | Gets the ContainerBuilder by hacking the Drupal kernel.
@return
The container builder. | [
"Gets",
"the",
"ContainerBuilder",
"by",
"hacking",
"the",
"Drupal",
"kernel",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/ContainerBuilderGetter.php#L21-L36 |
41,991 | drupal-code-builder/drupal-code-builder | Task/Collect/CodeAnalyser.php | CodeAnalyser.classIsUsable | public function classIsUsable($qualified_classname) {
// Set up the script with its autoloader if not already done so. We keep the
// resource to the process open between calls to this method.
// This means we only need to start a new process at the start of a request
// to DCB and after a bad class has caused the script to crash.
if (!is_resource($this->checking_script_resource)) {
$this->setupScript();
}
// Write the class to check to the script's STDIN.
$status = $this->sendCommand('CLASS', $qualified_classname);
if (!$status) {
// The process has crashed.
// Clean up so the script is reinitialized the next time this method is
// called.
$this->closeScript();
}
// Return the status of the class check: TRUE means the class is usable,
// FALSE means it is broken and a class_exists() causes a crash.
return $status;
} | php | public function classIsUsable($qualified_classname) {
// Set up the script with its autoloader if not already done so. We keep the
// resource to the process open between calls to this method.
// This means we only need to start a new process at the start of a request
// to DCB and after a bad class has caused the script to crash.
if (!is_resource($this->checking_script_resource)) {
$this->setupScript();
}
// Write the class to check to the script's STDIN.
$status = $this->sendCommand('CLASS', $qualified_classname);
if (!$status) {
// The process has crashed.
// Clean up so the script is reinitialized the next time this method is
// called.
$this->closeScript();
}
// Return the status of the class check: TRUE means the class is usable,
// FALSE means it is broken and a class_exists() causes a crash.
return $status;
} | [
"public",
"function",
"classIsUsable",
"(",
"$",
"qualified_classname",
")",
"{",
"// Set up the script with its autoloader if not already done so. We keep the",
"// resource to the process open between calls to this method.",
"// This means we only need to start a new process at the start of a ... | Determines whether a class may be instantiated safely.
This is needed because:
- lots of contrib modules have plugins that simply crash on class load,
typically because they fail the interface implementation.
- modules can have services which are meant for another non-dependent
module's use, and which can thus implement interfaces or inherit from
classes which are not present. For example, in the case of a tagged
service, if the collecting module is not enabled, we have no way of
detecting that the service's tag is a service collector tag.
@param string $qualified_classname
The fully-qualified class name, without the initial \.
@return boolean
TRUE if the class may be used (but note this does not say whether it
actually exists); FALSE if the class should not be used as attempting to
will cause a PHP fatal error. | [
"Determines",
"whether",
"a",
"class",
"may",
"be",
"instantiated",
"safely",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L65-L87 |
41,992 | drupal-code-builder/drupal-code-builder | Task/Collect/CodeAnalyser.php | CodeAnalyser.setupScript | protected function setupScript() {
// The PHP that proc_open() will find may not be the same one as run by
// the webserver, and indeed, on some systems may be an out-of-date version,
// so detect the PHP that we're currently running and ensure we use that.
$php = PHP_BINDIR . '/php';
$script_name = __DIR__ . '/../../class_safety_checker.php';
$drupal_root = $this->environment->getRoot();
$autoloader_filepath = $drupal_root . '/autoload.php';
// We need to pass all the dynamic namespaces to the script, as Composer's
// generated autoloader knows only about /vendor and /core/lib, but not
// modules.
// This code is taken from DrupalKernel::attachSynthetic().
$container = $this->environment->getContainer();
$namespaces = $container->getParameter('container.namespaces');
$psr4 = [];
foreach ($namespaces as $prefix => $paths) {
if (is_array($paths)) {
foreach ($paths as $key => $value) {
$paths[$key] = $drupal_root . '/' . $value;
}
}
elseif (is_string($paths)) {
$paths = $drupal_root . '/' . $paths;
}
// Build a list of data to pass to the script on STDIN.
// $paths is never an array, AFAICT.
$psr4[] = $prefix . '\\' . '::' . $paths;
}
// Debug option for the script.
$debug_int = (int) $this->debug;
$command = "{$php} {$script_name} '{$autoloader_filepath}' {$debug_int}";
// Open pipes for both input and output.
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w")
);
$this->checking_script_resource = proc_open($command, $descriptorspec, $this->pipes);
if (!is_resource($this->checking_script_resource)) {
throw new \Exception("Could not create process for classIsUsable().");
}
foreach ($psr4 as $line) {
$this->sendCommand('PSR4', $line);
}
} | php | protected function setupScript() {
// The PHP that proc_open() will find may not be the same one as run by
// the webserver, and indeed, on some systems may be an out-of-date version,
// so detect the PHP that we're currently running and ensure we use that.
$php = PHP_BINDIR . '/php';
$script_name = __DIR__ . '/../../class_safety_checker.php';
$drupal_root = $this->environment->getRoot();
$autoloader_filepath = $drupal_root . '/autoload.php';
// We need to pass all the dynamic namespaces to the script, as Composer's
// generated autoloader knows only about /vendor and /core/lib, but not
// modules.
// This code is taken from DrupalKernel::attachSynthetic().
$container = $this->environment->getContainer();
$namespaces = $container->getParameter('container.namespaces');
$psr4 = [];
foreach ($namespaces as $prefix => $paths) {
if (is_array($paths)) {
foreach ($paths as $key => $value) {
$paths[$key] = $drupal_root . '/' . $value;
}
}
elseif (is_string($paths)) {
$paths = $drupal_root . '/' . $paths;
}
// Build a list of data to pass to the script on STDIN.
// $paths is never an array, AFAICT.
$psr4[] = $prefix . '\\' . '::' . $paths;
}
// Debug option for the script.
$debug_int = (int) $this->debug;
$command = "{$php} {$script_name} '{$autoloader_filepath}' {$debug_int}";
// Open pipes for both input and output.
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w")
);
$this->checking_script_resource = proc_open($command, $descriptorspec, $this->pipes);
if (!is_resource($this->checking_script_resource)) {
throw new \Exception("Could not create process for classIsUsable().");
}
foreach ($psr4 as $line) {
$this->sendCommand('PSR4', $line);
}
} | [
"protected",
"function",
"setupScript",
"(",
")",
"{",
"// The PHP that proc_open() will find may not be the same one as run by",
"// the webserver, and indeed, on some systems may be an out-of-date version,",
"// so detect the PHP that we're currently running and ensure we use that.",
"$",
"php... | Starts a process running the class safety script. | [
"Starts",
"a",
"process",
"running",
"the",
"class",
"safety",
"script",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L92-L143 |
41,993 | drupal-code-builder/drupal-code-builder | Task/Collect/CodeAnalyser.php | CodeAnalyser.sendCommand | protected function sendCommand($command, $payload) {
fwrite($this->pipes[0], $command . ':' . $payload . PHP_EOL);
$status_line = trim(fgets($this->pipes[1]));
// An empty status line means the script has stopped responding, and has
// presumably crashed.
if (empty($status_line)) {
return FALSE;
}
// An expected status line that matches the sent command means everything
// went fine.
if ($status_line == "$command OK") {
return TRUE;
}
// If something's gone wrong, get any further output from the script so we
// can see error messages.
while ($line = fgets($this->pipes[1])) {
dump($line);
}
throw new \Exception("Command $command with payload '$payload' failed.");
} | php | protected function sendCommand($command, $payload) {
fwrite($this->pipes[0], $command . ':' . $payload . PHP_EOL);
$status_line = trim(fgets($this->pipes[1]));
// An empty status line means the script has stopped responding, and has
// presumably crashed.
if (empty($status_line)) {
return FALSE;
}
// An expected status line that matches the sent command means everything
// went fine.
if ($status_line == "$command OK") {
return TRUE;
}
// If something's gone wrong, get any further output from the script so we
// can see error messages.
while ($line = fgets($this->pipes[1])) {
dump($line);
}
throw new \Exception("Command $command with payload '$payload' failed.");
} | [
"protected",
"function",
"sendCommand",
"(",
"$",
"command",
",",
"$",
"payload",
")",
"{",
"fwrite",
"(",
"$",
"this",
"->",
"pipes",
"[",
"0",
"]",
",",
"$",
"command",
".",
"':'",
".",
"$",
"payload",
".",
"PHP_EOL",
")",
";",
"$",
"status_line",
... | Send a single command to the script.
@param string $command
The command to send to the script. One of:
- 'PSR4': A PSR4 namespace and folder to add to the autoloader.
- 'CLASS': A class to check.
@param string $payload
The value to send to the script. Format depends on the command.
@return bool
Returns TRUE if the command was successful; FALSE if the process appears
to have crashed.
@throws \Exception
Throws an exception if the command failed. | [
"Send",
"a",
"single",
"command",
"to",
"the",
"script",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L162-L186 |
41,994 | drupal-code-builder/drupal-code-builder | Task/Collect/CodeAnalyser.php | CodeAnalyser.closeScript | public function closeScript() {
fclose($this->pipes[0]);
fclose($this->pipes[1]);
proc_close($this->checking_script_resource);
} | php | public function closeScript() {
fclose($this->pipes[0]);
fclose($this->pipes[1]);
proc_close($this->checking_script_resource);
} | [
"public",
"function",
"closeScript",
"(",
")",
"{",
"fclose",
"(",
"$",
"this",
"->",
"pipes",
"[",
"0",
"]",
")",
";",
"fclose",
"(",
"$",
"this",
"->",
"pipes",
"[",
"1",
"]",
")",
";",
"proc_close",
"(",
"$",
"this",
"->",
"checking_script_resourc... | Close the script.
Note this is called automatically when this object is destroyed. | [
"Close",
"the",
"script",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/CodeAnalyser.php#L193-L197 |
41,995 | drupal-code-builder/drupal-code-builder | Generator/FormattingTrait/PHPFormattingTrait.php | PHPFormattingTrait.docBlock | function docBlock($lines) {
if (!is_array($lines)) {
$lines = array($lines);
}
$lines = array_merge(
array("/**"),
array_map(function ($line) {
if (empty($line)) {
return ' *';
}
return " * $line";
}, $lines),
array(" */")
);
return $lines;
} | php | function docBlock($lines) {
if (!is_array($lines)) {
$lines = array($lines);
}
$lines = array_merge(
array("/**"),
array_map(function ($line) {
if (empty($line)) {
return ' *';
}
return " * $line";
}, $lines),
array(" */")
);
return $lines;
} | [
"function",
"docBlock",
"(",
"$",
"lines",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"lines",
")",
")",
"{",
"$",
"lines",
"=",
"array",
"(",
"$",
"lines",
")",
";",
"}",
"$",
"lines",
"=",
"array_merge",
"(",
"array",
"(",
"\"/**\"",
")",
... | Helper to format text as docblock.
@param @lines
An array of lines, or a single line of text. Lines to be normally indented
should have no leading whitespace.
@return
An array of lines for the docblock with start and end PHP comment markers. | [
"Helper",
"to",
"format",
"text",
"as",
"docblock",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/FormattingTrait/PHPFormattingTrait.php#L20-L37 |
41,996 | drupal-code-builder/drupal-code-builder | Generator/FormattingTrait/PHPFormattingTrait.php | PHPFormattingTrait.indentCodeLines | function indentCodeLines($lines, $indent = 1) {
$indent = str_repeat(' ', $indent);
$indented_lines = array_map(function ($line) use ($indent) {
return empty($line) ? $line : $indent . $line;
}, $lines);
return $indented_lines;
} | php | function indentCodeLines($lines, $indent = 1) {
$indent = str_repeat(' ', $indent);
$indented_lines = array_map(function ($line) use ($indent) {
return empty($line) ? $line : $indent . $line;
}, $lines);
return $indented_lines;
} | [
"function",
"indentCodeLines",
"(",
"$",
"lines",
",",
"$",
"indent",
"=",
"1",
")",
"{",
"$",
"indent",
"=",
"str_repeat",
"(",
"' '",
",",
"$",
"indent",
")",
";",
"$",
"indented_lines",
"=",
"array_map",
"(",
"function",
"(",
"$",
"line",
")",
"u... | Indent all the non-empty lines in a block of code.
@param array $lines
An array of code lines.
@param int $indent
(optional) The number of indentation levels to add. Defaults to 1, that
is, an indentation of two spaces.
@return
The array of code lines with the indentation applied. | [
"Indent",
"all",
"the",
"non",
"-",
"empty",
"lines",
"in",
"a",
"block",
"of",
"code",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Generator/FormattingTrait/PHPFormattingTrait.php#L51-L58 |
41,997 | drupal-code-builder/drupal-code-builder | Utility/NestedArray.php | NestedArray.filter | public static function filter(array $array, callable $callable = NULL) {
$array = is_callable($callable) ? array_filter($array, $callable) : array_filter($array);
foreach ($array as &$element) {
if (is_array($element)) {
$element = static::filter($element, $callable);
}
}
return $array;
} | php | public static function filter(array $array, callable $callable = NULL) {
$array = is_callable($callable) ? array_filter($array, $callable) : array_filter($array);
foreach ($array as &$element) {
if (is_array($element)) {
$element = static::filter($element, $callable);
}
}
return $array;
} | [
"public",
"static",
"function",
"filter",
"(",
"array",
"$",
"array",
",",
"callable",
"$",
"callable",
"=",
"NULL",
")",
"{",
"$",
"array",
"=",
"is_callable",
"(",
"$",
"callable",
")",
"?",
"array_filter",
"(",
"$",
"array",
",",
"$",
"callable",
")... | Filters a nested array recursively.
@param array $array
The filtered nested array.
@param callable|null $callable
The callable to apply for filtering.
@return array
The filtered array. | [
"Filters",
"a",
"nested",
"array",
"recursively",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Utility/NestedArray.php#L364-L373 |
41,998 | drupal-code-builder/drupal-code-builder | Environment/Drush.php | Drush.getHooksDirectorySettingHelper | private function getHooksDirectorySettingHelper() {
// Set the module folder based on variable.
// First try the drush 'data' option.
if (drush_get_option('data')) {
$directory = drush_get_option('data');
if ($directory) {
// In pure Drush, the hooks folder contains subfolder for hooks for
// each major version of Drupal.
if (substr($directory, -1, 1) != '/') {
$directory .= '/';
}
$directory .= $this->getCoreMajorVersion();
return $directory;
}
}
// Second, use the config setting, in case we're in drush, but the site has
// Module Builder running as a module.
$directory = $this->getSetting('data_directory', 'hooks');
return $directory;
} | php | private function getHooksDirectorySettingHelper() {
// Set the module folder based on variable.
// First try the drush 'data' option.
if (drush_get_option('data')) {
$directory = drush_get_option('data');
if ($directory) {
// In pure Drush, the hooks folder contains subfolder for hooks for
// each major version of Drupal.
if (substr($directory, -1, 1) != '/') {
$directory .= '/';
}
$directory .= $this->getCoreMajorVersion();
return $directory;
}
}
// Second, use the config setting, in case we're in drush, but the site has
// Module Builder running as a module.
$directory = $this->getSetting('data_directory', 'hooks');
return $directory;
} | [
"private",
"function",
"getHooksDirectorySettingHelper",
"(",
")",
"{",
"// Set the module folder based on variable.",
"// First try the drush 'data' option.",
"if",
"(",
"drush_get_option",
"(",
"'data'",
")",
")",
"{",
"$",
"directory",
"=",
"drush_get_option",
"(",
"'dat... | Get the hooks directory.
On Drush, this can come from several places, in the following order of
preference:
- The Drush --data option. This allows use of a central store of hook data
that needs only be downloaded once for all Drupal sites. Subdirectories
are made for each major version.
- The Module Builder UI's variable. This will only be set if module
builder has been installed as a Drupal module on the current site. | [
"Get",
"the",
"hooks",
"directory",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Environment/Drush.php#L35-L54 |
41,999 | drupal-code-builder/drupal-code-builder | Task/Collect/AdminRoutesCollector.php | AdminRoutesCollector.collect | public function collect($job_list) {
$route_provider = \Drupal::service('router.route_provider');
// TODO: figure out how on earth getRoutesByPattern() is meant to work!
$routes = $route_provider->getAllRoutes();
$admin_routes = [];
foreach ($routes as $route_name => $route) {
$controller = $route->getDefault('_controller');
if ($controller == '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage') {
$route_path = $route->getPath();
// Skip the '/admin' path, as you don't put items there.
if ($route_path == '/admin') {
continue;
}
$admin_routes[$route_name] = [
'route_name' => $route_name,
'path' => $route_path,
'title' => $route->getDefault('_title'),
];
}
}
return $admin_routes;
} | php | public function collect($job_list) {
$route_provider = \Drupal::service('router.route_provider');
// TODO: figure out how on earth getRoutesByPattern() is meant to work!
$routes = $route_provider->getAllRoutes();
$admin_routes = [];
foreach ($routes as $route_name => $route) {
$controller = $route->getDefault('_controller');
if ($controller == '\Drupal\system\Controller\SystemController::systemAdminMenuBlockPage') {
$route_path = $route->getPath();
// Skip the '/admin' path, as you don't put items there.
if ($route_path == '/admin') {
continue;
}
$admin_routes[$route_name] = [
'route_name' => $route_name,
'path' => $route_path,
'title' => $route->getDefault('_title'),
];
}
}
return $admin_routes;
} | [
"public",
"function",
"collect",
"(",
"$",
"job_list",
")",
"{",
"$",
"route_provider",
"=",
"\\",
"Drupal",
"::",
"service",
"(",
"'router.route_provider'",
")",
";",
"// TODO: figure out how on earth getRoutesByPattern() is meant to work!",
"$",
"routes",
"=",
"$",
... | Gets definitions of admin routes that show submenu blocks.
@return array
An array whose keys are the route names, and whose values are arrays
containing:
- 'route_name': The route name.
- 'path': The path.
- 'title': The route title. | [
"Gets",
"definitions",
"of",
"admin",
"routes",
"that",
"show",
"submenu",
"blocks",
"."
] | 7a9b9895218c729cd5f4c1dba75010f53c7da92e | https://github.com/drupal-code-builder/drupal-code-builder/blob/7a9b9895218c729cd5f4c1dba75010f53c7da92e/Task/Collect/AdminRoutesCollector.php#L41-L66 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.