repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6
values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1
value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
thephpleague/iso3166 | src/ISO3166.php | ISO3166.numeric | public function numeric($numeric)
{
Guards::guardAgainstInvalidNumeric($numeric);
return $this->lookup(self::KEY_NUMERIC, $numeric);
} | php | public function numeric($numeric)
{
Guards::guardAgainstInvalidNumeric($numeric);
return $this->lookup(self::KEY_NUMERIC, $numeric);
} | [
"public",
"function",
"numeric",
"(",
"$",
"numeric",
")",
"{",
"Guards",
"::",
"guardAgainstInvalidNumeric",
"(",
"$",
"numeric",
")",
";",
"return",
"$",
"this",
"->",
"lookup",
"(",
"self",
"::",
"KEY_NUMERIC",
",",
"$",
"numeric",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/thephpleague/iso3166/blob/0e8b0e54fc73c40b93d23dbfe0945e250dd034b0/src/ISO3166.php#L71-L76 |
thephpleague/iso3166 | src/ISO3166.php | ISO3166.iterator | public function iterator($key = self::KEY_ALPHA2)
{
if (!in_array($key, $this->keys, true)) {
throw new DomainException(sprintf(
'Invalid value for $indexBy, got "%s", expected one of: %s',
$key,
implode(', ', $this->keys)
));
}
foreach ($this->countries as $country) {
yield $country[$key] => $country;
}
} | php | public function iterator($key = self::KEY_ALPHA2)
{
if (!in_array($key, $this->keys, true)) {
throw new DomainException(sprintf(
'Invalid value for $indexBy, got "%s", expected one of: %s',
$key,
implode(', ', $this->keys)
));
}
foreach ($this->countries as $country) {
yield $country[$key] => $country;
}
} | [
"public",
"function",
"iterator",
"(",
"$",
"key",
"=",
"self",
"::",
"KEY_ALPHA2",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"keys",
",",
"true",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"sprintf",
... | @param string $key
@throws \League\ISO3166\Exception\DomainException if an invalid key is specified
@return \Generator | [
"@param",
"string",
"$key"
] | train | https://github.com/thephpleague/iso3166/blob/0e8b0e54fc73c40b93d23dbfe0945e250dd034b0/src/ISO3166.php#L93-L106 |
thephpleague/iso3166 | src/ISO3166.php | ISO3166.lookup | private function lookup($key, $value)
{
foreach ($this->countries as $country) {
if (0 === strcasecmp($value, $country[$key])) {
return $country;
}
}
throw new OutOfBoundsException(
sprintf('No "%s" key found matching: %s', $key, $value)
);
} | php | private function lookup($key, $value)
{
foreach ($this->countries as $country) {
if (0 === strcasecmp($value, $country[$key])) {
return $country;
}
}
throw new OutOfBoundsException(
sprintf('No "%s" key found matching: %s', $key, $value)
);
} | [
"private",
"function",
"lookup",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"countries",
"as",
"$",
"country",
")",
"{",
"if",
"(",
"0",
"===",
"strcasecmp",
"(",
"$",
"value",
",",
"$",
"country",
"[",
"$",
... | Lookup ISO3166-1 data by given identifier.
Looks for a match against the given key for each entry in the dataset.
@param string $key
@param string $value
@throws \League\ISO3166\Exception\OutOfBoundsException if key does not exist in dataset
@return array | [
"Lookup",
"ISO3166",
"-",
"1",
"data",
"by",
"given",
"identifier",
"."
] | train | https://github.com/thephpleague/iso3166/blob/0e8b0e54fc73c40b93d23dbfe0945e250dd034b0/src/ISO3166.php#L146-L157 |
thephpleague/iso3166 | src/ISO3166DataValidator.php | ISO3166DataValidator.assertEntryHasRequiredKeys | private function assertEntryHasRequiredKeys(array $entry)
{
if (!isset($entry[ISO3166::KEY_ALPHA2])) {
throw new DomainException('Each data entry must have a valid alpha2 key.');
}
Guards::guardAgainstInvalidAlpha2($entry[ISO3166::KEY_ALPHA2]);
if (!isset($entry[ISO3166::KEY_ALPHA3])) {
throw new DomainException('Each data entry must have a valid alpha3 key.');
}
Guards::guardAgainstInvalidAlpha3($entry[ISO3166::KEY_ALPHA3]);
if (!isset($entry[ISO3166::KEY_NUMERIC])) {
throw new DomainException('Each data entry must have a valid numeric key.');
}
Guards::guardAgainstInvalidNumeric($entry[ISO3166::KEY_NUMERIC]);
} | php | private function assertEntryHasRequiredKeys(array $entry)
{
if (!isset($entry[ISO3166::KEY_ALPHA2])) {
throw new DomainException('Each data entry must have a valid alpha2 key.');
}
Guards::guardAgainstInvalidAlpha2($entry[ISO3166::KEY_ALPHA2]);
if (!isset($entry[ISO3166::KEY_ALPHA3])) {
throw new DomainException('Each data entry must have a valid alpha3 key.');
}
Guards::guardAgainstInvalidAlpha3($entry[ISO3166::KEY_ALPHA3]);
if (!isset($entry[ISO3166::KEY_NUMERIC])) {
throw new DomainException('Each data entry must have a valid numeric key.');
}
Guards::guardAgainstInvalidNumeric($entry[ISO3166::KEY_NUMERIC]);
} | [
"private",
"function",
"assertEntryHasRequiredKeys",
"(",
"array",
"$",
"entry",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"entry",
"[",
"ISO3166",
"::",
"KEY_ALPHA2",
"]",
")",
")",
"{",
"throw",
"new",
"DomainException",
"(",
"'Each data entry must have a... | @param array $entry
@throws \League\ISO3166\Exception\DomainException if given data entry does not have all the required keys | [
"@param",
"array",
"$entry"
] | train | https://github.com/thephpleague/iso3166/blob/0e8b0e54fc73c40b93d23dbfe0945e250dd034b0/src/ISO3166DataValidator.php#L35-L54 |
giggsey/Locale | src/Locale.php | Locale.getRegion | public static function getRegion($locale)
{
$parts = explode('-', str_replace('_', '-', $locale));
if (count($parts) === 1) {
return '';
}
$region = end($parts);
if (strlen($region) === 4) {
return '';
}
if ($region === 'POSIX') {
$region = 'US';
}
return strtoupper($region);
} | php | public static function getRegion($locale)
{
$parts = explode('-', str_replace('_', '-', $locale));
if (count($parts) === 1) {
return '';
}
$region = end($parts);
if (strlen($region) === 4) {
return '';
}
if ($region === 'POSIX') {
$region = 'US';
}
return strtoupper($region);
} | [
"public",
"static",
"function",
"getRegion",
"(",
"$",
"locale",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'-'",
",",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"$",
"locale",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"===",
... | Get the region for the input locale
@param string $locale Input locale (e.g. de-CH-1991)
@return string Region (e.g. CH) | [
"Get",
"the",
"region",
"for",
"the",
"input",
"locale"
] | train | https://github.com/giggsey/Locale/blob/b8030fc8df13cdfbecba318588de2d52b49c9b50/src/Locale.php#L28-L47 |
giggsey/Locale | src/Locale.php | Locale.getDisplayRegion | public static function getDisplayRegion($locale, $inLocale)
{
$dataDir = __DIR__ . DIRECTORY_SEPARATOR . static::$dataDir;
// Convert $locale into a region
$region = static::getRegion($locale);
$regionList = require $dataDir . '_list.php';
/*
* Loop through each part of the $inLocale, and see if we have data for that locale
*
* E.g zh-Hans-HK will look for zh-Hanks-HK, zh-Hanks, then finally zh
*/
$fallbackParts = explode('-', str_replace('_', '-', $inLocale));
$filesToSearch = array();
$i = count($fallbackParts);
while ($i > 0) {
$searchLocale = strtolower(implode('-', $fallbackParts));
if (isset($regionList[$searchLocale])) {
$filesToSearch[] = $searchLocale;
}
array_pop($fallbackParts);
$i--;
}
/*
* Load data files, and load the region (if it exists) from it
*/
foreach ($filesToSearch as $fileToSearch) {
// Load data file
$data = require $dataDir . $fileToSearch . '.php';
if (isset($data[$region])) {
return $data[$region];
}
}
return '';
} | php | public static function getDisplayRegion($locale, $inLocale)
{
$dataDir = __DIR__ . DIRECTORY_SEPARATOR . static::$dataDir;
// Convert $locale into a region
$region = static::getRegion($locale);
$regionList = require $dataDir . '_list.php';
/*
* Loop through each part of the $inLocale, and see if we have data for that locale
*
* E.g zh-Hans-HK will look for zh-Hanks-HK, zh-Hanks, then finally zh
*/
$fallbackParts = explode('-', str_replace('_', '-', $inLocale));
$filesToSearch = array();
$i = count($fallbackParts);
while ($i > 0) {
$searchLocale = strtolower(implode('-', $fallbackParts));
if (isset($regionList[$searchLocale])) {
$filesToSearch[] = $searchLocale;
}
array_pop($fallbackParts);
$i--;
}
/*
* Load data files, and load the region (if it exists) from it
*/
foreach ($filesToSearch as $fileToSearch) {
// Load data file
$data = require $dataDir . $fileToSearch . '.php';
if (isset($data[$region])) {
return $data[$region];
}
}
return '';
} | [
"public",
"static",
"function",
"getDisplayRegion",
"(",
"$",
"locale",
",",
"$",
"inLocale",
")",
"{",
"$",
"dataDir",
"=",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"static",
"::",
"$",
"dataDir",
";",
"// Convert $locale into a region",
"$",
"region",
"=",
... | Get the localised display name for the region of the input locale
@param string $locale The locale to return a display region for
@param string $inLocale Format locale to display the region name
@return string Display name for the region, or an empty string if no result could be found | [
"Get",
"the",
"localised",
"display",
"name",
"for",
"the",
"region",
"of",
"the",
"input",
"locale"
] | train | https://github.com/giggsey/Locale/blob/b8030fc8df13cdfbecba318588de2d52b49c9b50/src/Locale.php#L56-L99 |
giggsey/Locale | src/Locale.php | Locale.getAllCountriesForLocale | public static function getAllCountriesForLocale($locale)
{
$dataDir = __DIR__ . DIRECTORY_SEPARATOR . static::$dataDir;
$regionList = require $dataDir . '_list.php';
if (!isset($regionList[$locale])) {
throw new \RuntimeException("Locale is not supported");
}
/*
* Loop through each part of the $locale, and load data for that locale
*
* E.g zh-Hans-HK will look for zh-Hanks-HK, zh-Hanks, then finally zh
*/
$fallbackParts = explode('-', str_replace('_', '-', $locale));
$filesToSearch = array();
$i = count($fallbackParts);
while ($i > 0) {
$searchLocale = strtolower(implode('-', $fallbackParts));
if (isset($regionList[$searchLocale])) {
$filesToSearch[] = $searchLocale;
}
array_pop($fallbackParts);
$i--;
}
/*
* Load data files, and load the region (if it exists) from it
*/
$returnData = array();
foreach ($filesToSearch as $fileToSearch) {
// Load data file
$data = require $dataDir . $fileToSearch . '.php';
$returnData += $data;
}
ksort($returnData);
return $returnData;
} | php | public static function getAllCountriesForLocale($locale)
{
$dataDir = __DIR__ . DIRECTORY_SEPARATOR . static::$dataDir;
$regionList = require $dataDir . '_list.php';
if (!isset($regionList[$locale])) {
throw new \RuntimeException("Locale is not supported");
}
/*
* Loop through each part of the $locale, and load data for that locale
*
* E.g zh-Hans-HK will look for zh-Hanks-HK, zh-Hanks, then finally zh
*/
$fallbackParts = explode('-', str_replace('_', '-', $locale));
$filesToSearch = array();
$i = count($fallbackParts);
while ($i > 0) {
$searchLocale = strtolower(implode('-', $fallbackParts));
if (isset($regionList[$searchLocale])) {
$filesToSearch[] = $searchLocale;
}
array_pop($fallbackParts);
$i--;
}
/*
* Load data files, and load the region (if it exists) from it
*/
$returnData = array();
foreach ($filesToSearch as $fileToSearch) {
// Load data file
$data = require $dataDir . $fileToSearch . '.php';
$returnData += $data;
}
ksort($returnData);
return $returnData;
} | [
"public",
"static",
"function",
"getAllCountriesForLocale",
"(",
"$",
"locale",
")",
"{",
"$",
"dataDir",
"=",
"__DIR__",
".",
"DIRECTORY_SEPARATOR",
".",
"static",
"::",
"$",
"dataDir",
";",
"$",
"regionList",
"=",
"require",
"$",
"dataDir",
".",
"'_list.php'... | Load a list of all countries supported by a particular Locale
@param string $locale
@return string[] Associative array of Country Code => Country Name
@throws \RuntimeException On an invalid region | [
"Load",
"a",
"list",
"of",
"all",
"countries",
"supported",
"by",
"a",
"particular",
"Locale"
] | train | https://github.com/giggsey/Locale/blob/b8030fc8df13cdfbecba318588de2d52b49c9b50/src/Locale.php#L128-L173 |
giggsey/Locale | build/Build/DataBuilder.php | DataBuilder.checkDirectories | private function checkDirectories($inputDir, $outputDir)
{
if (!is_dir($inputDir)) {
throw new InvalidArgumentException(sprintf("Unable to find input directory: %s", $inputDir));
}
if (!is_dir($outputDir)) {
// Try to create output directory
if (mkdir($outputDir) === false) {
throw new RuntimeException(sprintf("Unable to create output directory: %s", $outputDir));
}
}
} | php | private function checkDirectories($inputDir, $outputDir)
{
if (!is_dir($inputDir)) {
throw new InvalidArgumentException(sprintf("Unable to find input directory: %s", $inputDir));
}
if (!is_dir($outputDir)) {
// Try to create output directory
if (mkdir($outputDir) === false) {
throw new RuntimeException(sprintf("Unable to create output directory: %s", $outputDir));
}
}
} | [
"private",
"function",
"checkDirectories",
"(",
"$",
"inputDir",
",",
"$",
"outputDir",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"inputDir",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"\"Unable to find input directory: %... | Check and create directories
@param string $inputDir
@param string $outputDir
@codeCoverageIgnore Ignore for unit test coverage | [
"Check",
"and",
"create",
"directories"
] | train | https://github.com/giggsey/Locale/blob/b8030fc8df13cdfbecba318588de2d52b49c9b50/build/Build/DataBuilder.php#L127-L139 |
giggsey/Locale | build/Build/DataBuilder.php | DataBuilder.loadLocales | private function loadLocales($inputDir)
{
$localeList = array();
foreach (scandir($inputDir) as $item) {
if (substr($item, 0, 1) !== '.' && is_dir($inputDir . $item)) {
if (in_array($item, $this->ignoredLocales)) {
// Skip over any ignored locales
continue;
}
$localeList[] = $item;
}
}
return $localeList;
} | php | private function loadLocales($inputDir)
{
$localeList = array();
foreach (scandir($inputDir) as $item) {
if (substr($item, 0, 1) !== '.' && is_dir($inputDir . $item)) {
if (in_array($item, $this->ignoredLocales)) {
// Skip over any ignored locales
continue;
}
$localeList[] = $item;
}
}
return $localeList;
} | [
"private",
"function",
"loadLocales",
"(",
"$",
"inputDir",
")",
"{",
"$",
"localeList",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"scandir",
"(",
"$",
"inputDir",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"item",
",",
"0"... | Load Locale list from the source data
@param string $inputDir Input Directory
@return array List of Locales | [
"Load",
"Locale",
"list",
"from",
"the",
"source",
"data"
] | train | https://github.com/giggsey/Locale/blob/b8030fc8df13cdfbecba318588de2d52b49c9b50/build/Build/DataBuilder.php#L147-L163 |
bmitch/churn-php | src/Factories/ProcessFactory.php | ProcessFactory.createGitCommitProcess | public function createGitCommitProcess(File $file): ChurnProcess
{
$process = new Process(
'git -C ' . escapeshellarg(getcwd()) . ' log --since=' .
escapeshellarg($this->commitsSince) . ' --name-only --pretty=format: ' .
escapeshellarg($file->getFullPath()) . ' | sort | uniq -c | sort -nr'
);
return new ChurnProcess($file, $process, 'GitCommitProcess');
} | php | public function createGitCommitProcess(File $file): ChurnProcess
{
$process = new Process(
'git -C ' . escapeshellarg(getcwd()) . ' log --since=' .
escapeshellarg($this->commitsSince) . ' --name-only --pretty=format: ' .
escapeshellarg($file->getFullPath()) . ' | sort | uniq -c | sort -nr'
);
return new ChurnProcess($file, $process, 'GitCommitProcess');
} | [
"public",
"function",
"createGitCommitProcess",
"(",
"File",
"$",
"file",
")",
":",
"ChurnProcess",
"{",
"$",
"process",
"=",
"new",
"Process",
"(",
"'git -C '",
".",
"escapeshellarg",
"(",
"getcwd",
"(",
")",
")",
".",
"' log --since='",
".",
"escapeshellarg"... | Creates a Git Commit Process that will run on $file.
@param File $file File that the process will execute on.
@return ChurnProcess | [
"Creates",
"a",
"Git",
"Commit",
"Process",
"that",
"will",
"run",
"on",
"$file",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Factories/ProcessFactory.php#L31-L40 |
bmitch/churn-php | src/Factories/ProcessFactory.php | ProcessFactory.createCyclomaticComplexityProcess | public function createCyclomaticComplexityProcess(File $file): ChurnProcess
{
$rootFolder = __DIR__ . '/../../bin/';
$process = new Process(
'php ' . escapeshellarg($rootFolder . 'CyclomaticComplexityAssessorRunner') .
' ' . escapeshellarg($file->getFullPath())
);
return new ChurnProcess($file, $process, 'CyclomaticComplexityProcess');
} | php | public function createCyclomaticComplexityProcess(File $file): ChurnProcess
{
$rootFolder = __DIR__ . '/../../bin/';
$process = new Process(
'php ' . escapeshellarg($rootFolder . 'CyclomaticComplexityAssessorRunner') .
' ' . escapeshellarg($file->getFullPath())
);
return new ChurnProcess($file, $process, 'CyclomaticComplexityProcess');
} | [
"public",
"function",
"createCyclomaticComplexityProcess",
"(",
"File",
"$",
"file",
")",
":",
"ChurnProcess",
"{",
"$",
"rootFolder",
"=",
"__DIR__",
".",
"'/../../bin/'",
";",
"$",
"process",
"=",
"new",
"Process",
"(",
"'php '",
".",
"escapeshellarg",
"(",
... | Creates a Cyclomatic Complexity Process that will run on $file.
@param File $file File that the process will execute on.
@return ChurnProcess | [
"Creates",
"a",
"Cyclomatic",
"Complexity",
"Process",
"that",
"will",
"run",
"on",
"$file",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Factories/ProcessFactory.php#L47-L57 |
bmitch/churn-php | src/Results/Result.php | Result.getScore | public function getScore(int $maxCommits, int $maxComplexity): float
{
Assert::greaterThan($maxComplexity, 0);
Assert::greaterThan($maxCommits, 0);
/*
* Calculate the horizontal and vertical distance from the "top right"
* corner.
*/
$horizontalDistance = $maxCommits - $this->getCommits();
$verticalDistance = $maxComplexity - $this->getComplexity();
/*
* Normalize these values over time, we first divide by the maximum
* values, to always end up with distances between 0 and 1.
*/
$normalizedHorizontalDistance = $horizontalDistance / $maxCommits;
$normalizedVerticalDistance = $verticalDistance / $maxComplexity;
/*
* Calculate the distance of this class from the "top right" corner,
* using the simple formula A^2 + B^2 = C^2; or: C = sqrt(A^2 + B^2)).
*/
$distanceFromTopRightCorner = sqrt(
$normalizedHorizontalDistance ** 2
+ $normalizedVerticalDistance ** 2
);
/*
* The resulting value will be between 0 and sqrt(2). A short distance is bad,
* so in order to end up with a high score, we invert the value by
* subtracting it from 1.
*/
return round(1 - $distanceFromTopRightCorner, 3);
// @codingStandardsIgnoreEnd
} | php | public function getScore(int $maxCommits, int $maxComplexity): float
{
Assert::greaterThan($maxComplexity, 0);
Assert::greaterThan($maxCommits, 0);
/*
* Calculate the horizontal and vertical distance from the "top right"
* corner.
*/
$horizontalDistance = $maxCommits - $this->getCommits();
$verticalDistance = $maxComplexity - $this->getComplexity();
/*
* Normalize these values over time, we first divide by the maximum
* values, to always end up with distances between 0 and 1.
*/
$normalizedHorizontalDistance = $horizontalDistance / $maxCommits;
$normalizedVerticalDistance = $verticalDistance / $maxComplexity;
/*
* Calculate the distance of this class from the "top right" corner,
* using the simple formula A^2 + B^2 = C^2; or: C = sqrt(A^2 + B^2)).
*/
$distanceFromTopRightCorner = sqrt(
$normalizedHorizontalDistance ** 2
+ $normalizedVerticalDistance ** 2
);
/*
* The resulting value will be between 0 and sqrt(2). A short distance is bad,
* so in order to end up with a high score, we invert the value by
* subtracting it from 1.
*/
return round(1 - $distanceFromTopRightCorner, 3);
// @codingStandardsIgnoreEnd
} | [
"public",
"function",
"getScore",
"(",
"int",
"$",
"maxCommits",
",",
"int",
"$",
"maxComplexity",
")",
":",
"float",
"{",
"Assert",
"::",
"greaterThan",
"(",
"$",
"maxComplexity",
",",
"0",
")",
";",
"Assert",
"::",
"greaterThan",
"(",
"$",
"maxCommits",
... | Calculate the score.
@param int $maxCommits The highest number of commits out of any file scanned.
@param int $maxComplexity The maximum complexity out of any file scanned.
@return float
@codingStandardsIgnoreStart | [
"Calculate",
"the",
"score",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/Result.php#L73-L108 |
bmitch/churn-php | src/Results/ResultsParser.php | ResultsParser.parse | public function parse(Collection $completedProcesses): ResultCollection
{
$this->resultsCollection = new ResultCollection;
foreach ($completedProcesses as $file => $processes) {
$this->parseCompletedProcessesForFile($file, $processes);
}
return $this->resultsCollection;
} | php | public function parse(Collection $completedProcesses): ResultCollection
{
$this->resultsCollection = new ResultCollection;
foreach ($completedProcesses as $file => $processes) {
$this->parseCompletedProcessesForFile($file, $processes);
}
return $this->resultsCollection;
} | [
"public",
"function",
"parse",
"(",
"Collection",
"$",
"completedProcesses",
")",
":",
"ResultCollection",
"{",
"$",
"this",
"->",
"resultsCollection",
"=",
"new",
"ResultCollection",
";",
"foreach",
"(",
"$",
"completedProcesses",
"as",
"$",
"file",
"=>",
"$",
... | Turns a collection of completed processes into a
collection of parsed result objects.
@param Collection $completedProcesses Collection of completed processes.
@return ResultCollection | [
"Turns",
"a",
"collection",
"of",
"completed",
"processes",
"into",
"a",
"collection",
"of",
"parsed",
"result",
"objects",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/ResultsParser.php#L23-L32 |
bmitch/churn-php | src/Results/ResultsParser.php | ResultsParser.parseCompletedProcessesForFile | private function parseCompletedProcessesForFile(string $file, array $processes)
{
$commits = (integer) $this->parseCommits($processes['GitCommitProcess']);
$complexity = (integer) $processes['CyclomaticComplexityProcess']->getOutput();
$result = new Result([
'file' => $file,
'commits' => $commits,
'complexity' => $complexity,
]);
$this->resultsCollection->push($result);
} | php | private function parseCompletedProcessesForFile(string $file, array $processes)
{
$commits = (integer) $this->parseCommits($processes['GitCommitProcess']);
$complexity = (integer) $processes['CyclomaticComplexityProcess']->getOutput();
$result = new Result([
'file' => $file,
'commits' => $commits,
'complexity' => $complexity,
]);
$this->resultsCollection->push($result);
} | [
"private",
"function",
"parseCompletedProcessesForFile",
"(",
"string",
"$",
"file",
",",
"array",
"$",
"processes",
")",
"{",
"$",
"commits",
"=",
"(",
"integer",
")",
"$",
"this",
"->",
"parseCommits",
"(",
"$",
"processes",
"[",
"'GitCommitProcess'",
"]",
... | Parse the list of processes for a file.
@param string $file The file the processes were executed on.
@param array $processes The processes that were executed on the file.
@return void | [
"Parse",
"the",
"list",
"of",
"processes",
"for",
"a",
"file",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/ResultsParser.php#L40-L52 |
bmitch/churn-php | src/Results/ResultsParser.php | ResultsParser.parseCommits | private function parseCommits(ChurnProcess $process): int
{
$output = $process->getOutput();
preg_match("/([0-9]{1,})/", $output, $matches);
if (! isset($matches[1])) {
return 0;
}
return (integer) $matches[1];
} | php | private function parseCommits(ChurnProcess $process): int
{
$output = $process->getOutput();
preg_match("/([0-9]{1,})/", $output, $matches);
if (! isset($matches[1])) {
return 0;
}
return (integer) $matches[1];
} | [
"private",
"function",
"parseCommits",
"(",
"ChurnProcess",
"$",
"process",
")",
":",
"int",
"{",
"$",
"output",
"=",
"$",
"process",
"->",
"getOutput",
"(",
")",
";",
"preg_match",
"(",
"\"/([0-9]{1,})/\"",
",",
"$",
"output",
",",
"$",
"matches",
")",
... | Parse the number of commits on the file from the raw process output.
@param ChurnProcess $process Git Commit Count Process.
@return integer | [
"Parse",
"the",
"number",
"of",
"commits",
"on",
"the",
"file",
"from",
"the",
"raw",
"process",
"output",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/ResultsParser.php#L59-L67 |
bmitch/churn-php | src/Commands/ChurnCommand.php | ChurnCommand.execute | protected function execute(InputInterface $input, OutputInterface $output)
{
$content = (string) @file_get_contents($input->getOption('configuration'));
$config = Config::create(Yaml::parse($content) ?? []);
$filesCollection = (new FileManager($config->getFileExtensions(), $config->getFilesToIgnore()))
->getPhpFiles($this->getDirectoriesToScan($input, $config->getDirectoriesToScan()));
$completedProcesses = $this->processManager->process(
$filesCollection,
new ProcessFactory($config->getCommitsSince()),
$config->getParallelJobs()
);
$resultCollection = $this->resultsLogic->process(
$completedProcesses,
$config->getMinScoreToShow(),
$config->getFilesToShow()
);
$renderer = $this->renderFactory->getRenderer($input->getOption('format'));
$renderer->render($output, $resultCollection);
} | php | protected function execute(InputInterface $input, OutputInterface $output)
{
$content = (string) @file_get_contents($input->getOption('configuration'));
$config = Config::create(Yaml::parse($content) ?? []);
$filesCollection = (new FileManager($config->getFileExtensions(), $config->getFilesToIgnore()))
->getPhpFiles($this->getDirectoriesToScan($input, $config->getDirectoriesToScan()));
$completedProcesses = $this->processManager->process(
$filesCollection,
new ProcessFactory($config->getCommitsSince()),
$config->getParallelJobs()
);
$resultCollection = $this->resultsLogic->process(
$completedProcesses,
$config->getMinScoreToShow(),
$config->getFilesToShow()
);
$renderer = $this->renderFactory->getRenderer($input->getOption('format'));
$renderer->render($output, $resultCollection);
} | [
"protected",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"content",
"=",
"(",
"string",
")",
"@",
"file_get_contents",
"(",
"$",
"input",
"->",
"getOption",
"(",
"'configuration'",
")",
")... | Execute the command
@param InputInterface $input Input.
@param OutputInterface $output Output.
@return void | [
"Execute",
"the",
"command"
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Commands/ChurnCommand.php#L79-L101 |
bmitch/churn-php | src/Commands/ChurnCommand.php | ChurnCommand.getDirectoriesToScan | private function getDirectoriesToScan(InputInterface $input, array $dirsConfigured): array
{
$dirsProvidedAsArgs = $input->getArgument('paths');
if (count($dirsProvidedAsArgs) > 0) {
return $dirsProvidedAsArgs;
}
if (count($dirsConfigured) > 0) {
return $dirsConfigured;
}
throw new InvalidArgumentException(
'Provide the directories you want to scan as arguments, ' .
'or configure them under "directoriesToScan" in your churn.yml file.'
);
} | php | private function getDirectoriesToScan(InputInterface $input, array $dirsConfigured): array
{
$dirsProvidedAsArgs = $input->getArgument('paths');
if (count($dirsProvidedAsArgs) > 0) {
return $dirsProvidedAsArgs;
}
if (count($dirsConfigured) > 0) {
return $dirsConfigured;
}
throw new InvalidArgumentException(
'Provide the directories you want to scan as arguments, ' .
'or configure them under "directoriesToScan" in your churn.yml file.'
);
} | [
"private",
"function",
"getDirectoriesToScan",
"(",
"InputInterface",
"$",
"input",
",",
"array",
"$",
"dirsConfigured",
")",
":",
"array",
"{",
"$",
"dirsProvidedAsArgs",
"=",
"$",
"input",
"->",
"getArgument",
"(",
"'paths'",
")",
";",
"if",
"(",
"count",
... | Get the directories to scan.
@param InputInterface $input Input Interface.
@param array $dirsConfigured The directories configured to scan.
@throws InvalidArgumentException If paths argument invalid.
@return array When no directories to scan found. | [
"Get",
"the",
"directories",
"to",
"scan",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Commands/ChurnCommand.php#L110-L125 |
bmitch/churn-php | src/Renderers/Results/CsvResultsRenderer.php | CsvResultsRenderer.render | public function render(OutputInterface $output, ResultCollection $results)
{
$output->writeln($this->getHeader());
foreach ($results->toArray() as $result) {
$output->writeln(implode(';', [ '"'.$result[0].'"', $result[1], $result[2], $result[3] ]));
};
} | php | public function render(OutputInterface $output, ResultCollection $results)
{
$output->writeln($this->getHeader());
foreach ($results->toArray() as $result) {
$output->writeln(implode(';', [ '"'.$result[0].'"', $result[1], $result[2], $result[3] ]));
};
} | [
"public",
"function",
"render",
"(",
"OutputInterface",
"$",
"output",
",",
"ResultCollection",
"$",
"results",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"$",
"this",
"->",
"getHeader",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"results",
"->",
"toAr... | Renders the results.
@param OutputInterface $output Output Interface.
@param ResultCollection $results Result Collection.
@return void | [
"Renders",
"the",
"results",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Renderers/Results/CsvResultsRenderer.php#L16-L23 |
bmitch/churn-php | src/Logic/ResultsLogic.php | ResultsLogic.process | public function process(Collection $completedProcesses, float $minScore, int $filesToShow): ResultCollection
{
$resultCollection = $this->parser->parse($completedProcesses);
$resultCollection = $resultCollection->whereScoreAbove($minScore);
$resultCollection = $resultCollection->orderByScoreDesc();
return $resultCollection->take($filesToShow);
} | php | public function process(Collection $completedProcesses, float $minScore, int $filesToShow): ResultCollection
{
$resultCollection = $this->parser->parse($completedProcesses);
$resultCollection = $resultCollection->whereScoreAbove($minScore);
$resultCollection = $resultCollection->orderByScoreDesc();
return $resultCollection->take($filesToShow);
} | [
"public",
"function",
"process",
"(",
"Collection",
"$",
"completedProcesses",
",",
"float",
"$",
"minScore",
",",
"int",
"$",
"filesToShow",
")",
":",
"ResultCollection",
"{",
"$",
"resultCollection",
"=",
"$",
"this",
"->",
"parser",
"->",
"parse",
"(",
"$... | Processes the results into a ResultCollection.
@param Collection $completedProcesses Collection of completed processes.
@param float $minScore Minimum score to show.
@param integer $filesToShow Max number of files to show.
@return ResultCollection | [
"Processes",
"the",
"results",
"into",
"a",
"ResultCollection",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Logic/ResultsLogic.php#L33-L39 |
bmitch/churn-php | src/Managers/FileManager.php | FileManager.getPhpFiles | public function getPhpFiles(array $paths): FileCollection
{
$this->files = new FileCollection;
foreach ($paths as $path) {
$this->getPhpFilesFromPath($path);
}
return $this->files;
} | php | public function getPhpFiles(array $paths): FileCollection
{
$this->files = new FileCollection;
foreach ($paths as $path) {
$this->getPhpFilesFromPath($path);
}
return $this->files;
} | [
"public",
"function",
"getPhpFiles",
"(",
"array",
"$",
"paths",
")",
":",
"FileCollection",
"{",
"$",
"this",
"->",
"files",
"=",
"new",
"FileCollection",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"getPhpFilesFro... | Recursively finds all files with the .php extension in the provided
$paths and returns list as array.
@param array $paths Paths in which to look for .php files.
@return FileCollection | [
"Recursively",
"finds",
"all",
"files",
"with",
"the",
".",
"php",
"extension",
"in",
"the",
"provided",
"$paths",
"and",
"returns",
"list",
"as",
"array",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Managers/FileManager.php#L48-L56 |
bmitch/churn-php | src/Managers/FileManager.php | FileManager.getPhpFilesFromPath | private function getPhpFilesFromPath(string $path)
{
$directoryIterator = new RecursiveDirectoryIterator($path);
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
if (! in_array($file->getExtension(), $this->fileExtensions)) {
continue;
}
if ($this->fileShouldBeIgnored($file)) {
continue;
}
$this->files->push(new File(['displayPath' => $file->getPathName(), 'fullPath' => $file->getRealPath()]));
}
} | php | private function getPhpFilesFromPath(string $path)
{
$directoryIterator = new RecursiveDirectoryIterator($path);
foreach (new RecursiveIteratorIterator($directoryIterator) as $file) {
if (! in_array($file->getExtension(), $this->fileExtensions)) {
continue;
}
if ($this->fileShouldBeIgnored($file)) {
continue;
}
$this->files->push(new File(['displayPath' => $file->getPathName(), 'fullPath' => $file->getRealPath()]));
}
} | [
"private",
"function",
"getPhpFilesFromPath",
"(",
"string",
"$",
"path",
")",
"{",
"$",
"directoryIterator",
"=",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"new",
"RecursiveIteratorIterator",
"(",
"$",
"directoryIterator",
"... | Recursively finds all files with the .php extension in the provided
$path adds them to $this->files.
@param string $path Path in which to look for .php files.
@return void | [
"Recursively",
"finds",
"all",
"files",
"with",
"the",
".",
"php",
"extension",
"in",
"the",
"provided",
"$path",
"adds",
"them",
"to",
"$this",
"-",
">",
"files",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Managers/FileManager.php#L64-L78 |
bmitch/churn-php | src/Managers/FileManager.php | FileManager.fileShouldBeIgnored | private function fileShouldBeIgnored(SplFileInfo $file): bool
{
foreach ($this->filesToIgnore as $fileToIgnore) {
$regex = $this->patternToRegex($fileToIgnore);
if (preg_match("#{$regex}#", $file->getPathName())) {
return true;
}
}
return false;
} | php | private function fileShouldBeIgnored(SplFileInfo $file): bool
{
foreach ($this->filesToIgnore as $fileToIgnore) {
$regex = $this->patternToRegex($fileToIgnore);
if (preg_match("#{$regex}#", $file->getPathName())) {
return true;
}
}
return false;
} | [
"private",
"function",
"fileShouldBeIgnored",
"(",
"SplFileInfo",
"$",
"file",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filesToIgnore",
"as",
"$",
"fileToIgnore",
")",
"{",
"$",
"regex",
"=",
"$",
"this",
"->",
"patternToRegex",
"(",
"$",... | Determines if a file should be ignored.
@param \SplFileInfo $file File.
@return boolean | [
"Determines",
"if",
"a",
"file",
"should",
"be",
"ignored",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Managers/FileManager.php#L85-L95 |
bmitch/churn-php | src/Renderers/Results/ConsoleResultsRenderer.php | ConsoleResultsRenderer.render | public function render(OutputInterface $output, ResultCollection $results)
{
$output->write($this->getHeader());
$table = new Table($output);
$table->setHeaders(['File', 'Times Changed', 'Complexity', 'Score']);
$table->addRows($results->toArray());
$table->render();
$output->write("\n");
} | php | public function render(OutputInterface $output, ResultCollection $results)
{
$output->write($this->getHeader());
$table = new Table($output);
$table->setHeaders(['File', 'Times Changed', 'Complexity', 'Score']);
$table->addRows($results->toArray());
$table->render();
$output->write("\n");
} | [
"public",
"function",
"render",
"(",
"OutputInterface",
"$",
"output",
",",
"ResultCollection",
"$",
"results",
")",
"{",
"$",
"output",
"->",
"write",
"(",
"$",
"this",
"->",
"getHeader",
"(",
")",
")",
";",
"$",
"table",
"=",
"new",
"Table",
"(",
"$"... | Renders the results.
@param OutputInterface $output Output Interface.
@param ResultCollection $results Result Collection.
@return void | [
"Renders",
"the",
"results",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Renderers/Results/ConsoleResultsRenderer.php#L17-L27 |
bmitch/churn-php | src/Results/ResultCollection.php | ResultCollection.orderByScoreDesc | public function orderByScoreDesc(): self
{
return $this->sortByDesc(function (Result $result) {
return $result->getScore($this->maxCommits(), $this->maxComplexity());
});
} | php | public function orderByScoreDesc(): self
{
return $this->sortByDesc(function (Result $result) {
return $result->getScore($this->maxCommits(), $this->maxComplexity());
});
} | [
"public",
"function",
"orderByScoreDesc",
"(",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"sortByDesc",
"(",
"function",
"(",
"Result",
"$",
"result",
")",
"{",
"return",
"$",
"result",
"->",
"getScore",
"(",
"$",
"this",
"->",
"maxCommits",
"("... | Order results by their score in descending order.
@return self | [
"Order",
"results",
"by",
"their",
"score",
"in",
"descending",
"order",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/ResultCollection.php#L13-L18 |
bmitch/churn-php | src/Results/ResultCollection.php | ResultCollection.whereScoreAbove | public function whereScoreAbove(float $score)
{
return $this->filter(function (Result $result) use ($score) {
return $result->getScore($this->maxCommits(), $this->maxComplexity()) >= $score;
});
} | php | public function whereScoreAbove(float $score)
{
return $this->filter(function (Result $result) use ($score) {
return $result->getScore($this->maxCommits(), $this->maxComplexity()) >= $score;
});
} | [
"public",
"function",
"whereScoreAbove",
"(",
"float",
"$",
"score",
")",
"{",
"return",
"$",
"this",
"->",
"filter",
"(",
"function",
"(",
"Result",
"$",
"result",
")",
"use",
"(",
"$",
"score",
")",
"{",
"return",
"$",
"result",
"->",
"getScore",
"("... | Filter the results where their score is >= the provided $score
@param float $score Score to filter by.
@return static | [
"Filter",
"the",
"results",
"where",
"their",
"score",
"is",
">",
"=",
"the",
"provided",
"$score"
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/ResultCollection.php#L25-L30 |
bmitch/churn-php | src/Results/ResultCollection.php | ResultCollection.toArray | public function toArray(): array
{
return array_values(array_map(
function (Result $result) {
return array_merge(
$result->toArray(),
[$result->getScore($this->maxCommits(), $this->maxComplexity())]
);
},
$this->items
));
} | php | public function toArray(): array
{
return array_values(array_map(
function (Result $result) {
return array_merge(
$result->toArray(),
[$result->getScore($this->maxCommits(), $this->maxComplexity())]
);
},
$this->items
));
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"return",
"array_values",
"(",
"array_map",
"(",
"function",
"(",
"Result",
"$",
"result",
")",
"{",
"return",
"array_merge",
"(",
"$",
"result",
"->",
"toArray",
"(",
")",
",",
"[",
"$",
"r... | Override the original toArray() method to remove those disordered indices.
@return array | [
"Override",
"the",
"original",
"toArray",
"()",
"method",
"to",
"remove",
"those",
"disordered",
"indices",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Results/ResultCollection.php#L59-L70 |
bmitch/churn-php | src/Assessors/CyclomaticComplexity/CyclomaticComplexityAssessor.php | CyclomaticComplexityAssessor.assess | public function assess(string $filePath): int
{
$this->score = 0;
$contents = $this->getFileContents($filePath);
$this->hasAtLeastOneMethod($contents);
$this->countTheIfStatements($contents);
$this->countTheElseIfStatements($contents);
$this->countTheWhileLoops($contents);
$this->countTheForLoops($contents);
$this->countTheCaseStatements($contents);
$this->countTheTernaryOperators($contents);
$this->countTheLogicalAnds($contents);
$this->countTheLogicalOrs($contents);
if ($this->score === 0) {
$this->score = 1;
}
return $this->score;
} | php | public function assess(string $filePath): int
{
$this->score = 0;
$contents = $this->getFileContents($filePath);
$this->hasAtLeastOneMethod($contents);
$this->countTheIfStatements($contents);
$this->countTheElseIfStatements($contents);
$this->countTheWhileLoops($contents);
$this->countTheForLoops($contents);
$this->countTheCaseStatements($contents);
$this->countTheTernaryOperators($contents);
$this->countTheLogicalAnds($contents);
$this->countTheLogicalOrs($contents);
if ($this->score === 0) {
$this->score = 1;
}
return $this->score;
} | [
"public",
"function",
"assess",
"(",
"string",
"$",
"filePath",
")",
":",
"int",
"{",
"$",
"this",
"->",
"score",
"=",
"0",
";",
"$",
"contents",
"=",
"$",
"this",
"->",
"getFileContents",
"(",
"$",
"filePath",
")",
";",
"$",
"this",
"->",
"hasAtLeas... | Asses the files cyclomatic complexity.
@param string $filePath Path and file name.
@return integer | [
"Asses",
"the",
"files",
"cyclomatic",
"complexity",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Assessors/CyclomaticComplexity/CyclomaticComplexityAssessor.php#L18-L37 |
bmitch/churn-php | src/Assessors/CyclomaticComplexity/CyclomaticComplexityAssessor.php | CyclomaticComplexityAssessor.hasAtLeastOneMethod | protected function hasAtLeastOneMethod(string $contents)
{
preg_match("/[ ]function[ ]/", $contents, $matches);
if (isset($matches[0])) {
$this->score++;
}
} | php | protected function hasAtLeastOneMethod(string $contents)
{
preg_match("/[ ]function[ ]/", $contents, $matches);
if (isset($matches[0])) {
$this->score++;
}
} | [
"protected",
"function",
"hasAtLeastOneMethod",
"(",
"string",
"$",
"contents",
")",
"{",
"preg_match",
"(",
"\"/[ ]function[ ]/\"",
",",
"$",
"contents",
",",
"$",
"matches",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"matches",
"[",
"0",
"]",
")",
")",
"{... | Does the class have at least one method?
@param string $contents File contents.
@return void | [
"Does",
"the",
"class",
"have",
"at",
"least",
"one",
"method?"
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Assessors/CyclomaticComplexity/CyclomaticComplexityAssessor.php#L44-L50 |
bmitch/churn-php | src/Renderers/Results/JsonResultsRenderer.php | JsonResultsRenderer.render | public function render(OutputInterface $output, ResultCollection $results)
{
$data = array_map(function (array $result) {
return [
'file' => $result[0],
'commits' => $result[1],
'complexity' => $result[2],
'score' => $result[3],
];
}, $results->toArray());
$output->write(json_encode($data));
} | php | public function render(OutputInterface $output, ResultCollection $results)
{
$data = array_map(function (array $result) {
return [
'file' => $result[0],
'commits' => $result[1],
'complexity' => $result[2],
'score' => $result[3],
];
}, $results->toArray());
$output->write(json_encode($data));
} | [
"public",
"function",
"render",
"(",
"OutputInterface",
"$",
"output",
",",
"ResultCollection",
"$",
"results",
")",
"{",
"$",
"data",
"=",
"array_map",
"(",
"function",
"(",
"array",
"$",
"result",
")",
"{",
"return",
"[",
"'file'",
"=>",
"$",
"result",
... | Renders the results.
@param OutputInterface $output Output Interface.
@param ResultCollection $results Result Collection.
@return void | [
"Renders",
"the",
"results",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Renderers/Results/JsonResultsRenderer.php#L17-L29 |
bmitch/churn-php | src/Managers/ProcessManager.php | ProcessManager.process | public function process(
FileCollection $filesCollection,
ProcessFactory $processFactory,
int $numberOfParallelJobs
): Collection {
$this->filesCollection = $filesCollection;
$this->processFactory = $processFactory;
$this->runningProcesses = new Collection;
$this->completedProcessesArray = [];
while ($filesCollection->hasFiles() || $this->runningProcesses->count()) {
$this->getProcessResults($numberOfParallelJobs);
}
return new Collection($this->completedProcessesArray);
} | php | public function process(
FileCollection $filesCollection,
ProcessFactory $processFactory,
int $numberOfParallelJobs
): Collection {
$this->filesCollection = $filesCollection;
$this->processFactory = $processFactory;
$this->runningProcesses = new Collection;
$this->completedProcessesArray = [];
while ($filesCollection->hasFiles() || $this->runningProcesses->count()) {
$this->getProcessResults($numberOfParallelJobs);
}
return new Collection($this->completedProcessesArray);
} | [
"public",
"function",
"process",
"(",
"FileCollection",
"$",
"filesCollection",
",",
"ProcessFactory",
"$",
"processFactory",
",",
"int",
"$",
"numberOfParallelJobs",
")",
":",
"Collection",
"{",
"$",
"this",
"->",
"filesCollection",
"=",
"$",
"filesCollection",
"... | Run the processes to gather information.
@param FileCollection $filesCollection Collection of files.
@param ProcessFactory $processFactory Process Factory.
@param integer $numberOfParallelJobs Number of parallel jobs to run.
@return Collection | [
"Run",
"the",
"processes",
"to",
"gather",
"information",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Managers/ProcessManager.php#L42-L55 |
bmitch/churn-php | src/Managers/ProcessManager.php | ProcessManager.getProcessResults | private function getProcessResults(int $numberOfParallelJobs)
{
for ($index = $this->runningProcesses->count();
$this->filesCollection->hasFiles() > 0 && $index < $numberOfParallelJobs;
$index++) {
$file = $this->filesCollection->getNextFile();
$process = $this->processFactory->createGitCommitProcess($file);
$process->start();
$this->runningProcesses->put($process->getKey(), $process);
$process = $this->processFactory->createCyclomaticComplexityProcess($file);
$process->start();
$this->runningProcesses->put($process->getKey(), $process);
}
foreach ($this->runningProcesses as $file => $process) {
if ($process->isSuccessful()) {
$this->runningProcesses->forget($process->getKey());
$this->completedProcessesArray[$process->getFileName()][$process->getType()] = $process;
}
}
} | php | private function getProcessResults(int $numberOfParallelJobs)
{
for ($index = $this->runningProcesses->count();
$this->filesCollection->hasFiles() > 0 && $index < $numberOfParallelJobs;
$index++) {
$file = $this->filesCollection->getNextFile();
$process = $this->processFactory->createGitCommitProcess($file);
$process->start();
$this->runningProcesses->put($process->getKey(), $process);
$process = $this->processFactory->createCyclomaticComplexityProcess($file);
$process->start();
$this->runningProcesses->put($process->getKey(), $process);
}
foreach ($this->runningProcesses as $file => $process) {
if ($process->isSuccessful()) {
$this->runningProcesses->forget($process->getKey());
$this->completedProcessesArray[$process->getFileName()][$process->getType()] = $process;
}
}
} | [
"private",
"function",
"getProcessResults",
"(",
"int",
"$",
"numberOfParallelJobs",
")",
"{",
"for",
"(",
"$",
"index",
"=",
"$",
"this",
"->",
"runningProcesses",
"->",
"count",
"(",
")",
";",
"$",
"this",
"->",
"filesCollection",
"->",
"hasFiles",
"(",
... | Get the results of the processes.
@param integer $numberOfParallelJobs Number of parallel jobs to run.
@return void | [
"Get",
"the",
"results",
"of",
"the",
"processes",
"."
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Managers/ProcessManager.php#L62-L83 |
bmitch/churn-php | src/Factories/ResultsRendererFactory.php | ResultsRendererFactory.getRenderer | public function getRenderer(string $format): ResultsRendererInterface
{
if ($format === self::FORMAT_CSV) {
return new CsvResultsRenderer;
}
if ($format === self::FORMAT_JSON) {
return new JsonResultsRenderer;
}
if ($format === self::FORMAT_TEXT) {
return new ConsoleResultsRenderer;
}
throw new InvalidArgumentException('Invalid output format provided');
} | php | public function getRenderer(string $format): ResultsRendererInterface
{
if ($format === self::FORMAT_CSV) {
return new CsvResultsRenderer;
}
if ($format === self::FORMAT_JSON) {
return new JsonResultsRenderer;
}
if ($format === self::FORMAT_TEXT) {
return new ConsoleResultsRenderer;
}
throw new InvalidArgumentException('Invalid output format provided');
} | [
"public",
"function",
"getRenderer",
"(",
"string",
"$",
"format",
")",
":",
"ResultsRendererInterface",
"{",
"if",
"(",
"$",
"format",
"===",
"self",
"::",
"FORMAT_CSV",
")",
"{",
"return",
"new",
"CsvResultsRenderer",
";",
"}",
"if",
"(",
"$",
"format",
... | Render the results
@param string $format Format to render.
@throws InvalidArgumentException If output format invalid.
@return ResultsRendererInterface | [
"Render",
"the",
"results"
] | train | https://github.com/bmitch/churn-php/blob/309c663baa2e9716f555de3d69629e454d7e2db8/src/Factories/ResultsRendererFactory.php#L23-L38 |
phpstan/phpstan-strict-rules | src/Rules/Methods/MissingMethodReturnTypehintRule.php | MissingMethodReturnTypehintRule.processNode | public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
}
$methodReflection = $scope->getClassReflection()->getNativeMethod($node->name->name);
$messages = [];
$message = $this->checkMethodReturnType($methodReflection);
if ($message !== null) {
$messages[] = $message;
}
return $messages;
} | php | public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
}
$methodReflection = $scope->getClassReflection()->getNativeMethod($node->name->name);
$messages = [];
$message = $this->checkMethodReturnType($methodReflection);
if ($message !== null) {
$messages[] = $message;
}
return $messages;
} | [
"public",
"function",
"processNode",
"(",
"Node",
"$",
"node",
",",
"Scope",
"$",
"scope",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"scope",
"->",
"isInClass",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"PHPStan",
"\\",
"ShouldNotHappenException",
"... | @param \PhpParser\Node\Stmt\ClassMethod $node
@param \PHPStan\Analyser\Scope $scope
@return string[] errors | [
"@param",
"\\",
"PhpParser",
"\\",
"Node",
"\\",
"Stmt",
"\\",
"ClassMethod",
"$node",
"@param",
"\\",
"PHPStan",
"\\",
"Analyser",
"\\",
"Scope",
"$scope"
] | train | https://github.com/phpstan/phpstan-strict-rules/blob/12e0191f1edee174283d682a986c7b586206d3db/src/Rules/Methods/MissingMethodReturnTypehintRule.php#L28-L44 |
phpstan/phpstan-strict-rules | src/Rules/Properties/MissingPropertyTypehintRule.php | MissingPropertyTypehintRule.processNode | public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
}
$propertyReflection = $scope->getClassReflection()->getNativeProperty($node->name->name);
$returnType = $propertyReflection->getType();
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
return [
sprintf(
'Property %s::$%s has no typehint specified.',
$propertyReflection->getDeclaringClass()->getDisplayName(),
$node->name->name
),
];
}
return [];
} | php | public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
}
$propertyReflection = $scope->getClassReflection()->getNativeProperty($node->name->name);
$returnType = $propertyReflection->getType();
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
return [
sprintf(
'Property %s::$%s has no typehint specified.',
$propertyReflection->getDeclaringClass()->getDisplayName(),
$node->name->name
),
];
}
return [];
} | [
"public",
"function",
"processNode",
"(",
"Node",
"$",
"node",
",",
"Scope",
"$",
"scope",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"scope",
"->",
"isInClass",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"PHPStan",
"\\",
"ShouldNotHappenException",
"... | @param \PhpParser\Node\Stmt\PropertyProperty $node
@param \PHPStan\Analyser\Scope $scope
@return string[] errors | [
"@param",
"\\",
"PhpParser",
"\\",
"Node",
"\\",
"Stmt",
"\\",
"PropertyProperty",
"$node",
"@param",
"\\",
"PHPStan",
"\\",
"Analyser",
"\\",
"Scope",
"$scope"
] | train | https://github.com/phpstan/phpstan-strict-rules/blob/12e0191f1edee174283d682a986c7b586206d3db/src/Rules/Properties/MissingPropertyTypehintRule.php#L26-L45 |
phpstan/phpstan-strict-rules | src/Rules/Functions/MissingFunctionReturnTypehintRule.php | MissingFunctionReturnTypehintRule.processNode | public function processNode(Node $node, Scope $scope): array
{
$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name->name), $scope);
$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
return [
sprintf(
'Function %s() has no return typehint specified.',
$functionReflection->getName()
),
];
}
return [];
} | php | public function processNode(Node $node, Scope $scope): array
{
$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name->name), $scope);
$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {
return [
sprintf(
'Function %s() has no return typehint specified.',
$functionReflection->getName()
),
];
}
return [];
} | [
"public",
"function",
"processNode",
"(",
"Node",
"$",
"node",
",",
"Scope",
"$",
"scope",
")",
":",
"array",
"{",
"$",
"functionReflection",
"=",
"$",
"this",
"->",
"broker",
"->",
"getCustomFunction",
"(",
"new",
"Node",
"\\",
"Name",
"(",
"$",
"node",... | @param \PhpParser\Node\Stmt\Function_ $node
@param \PHPStan\Analyser\Scope $scope
@return string[] errors | [
"@param",
"\\",
"PhpParser",
"\\",
"Node",
"\\",
"Stmt",
"\\",
"Function_",
"$node",
"@param",
"\\",
"PHPStan",
"\\",
"Analyser",
"\\",
"Scope",
"$scope"
] | train | https://github.com/phpstan/phpstan-strict-rules/blob/12e0191f1edee174283d682a986c7b586206d3db/src/Rules/Functions/MissingFunctionReturnTypehintRule.php#L33-L48 |
phpstan/phpstan-strict-rules | src/Rules/Functions/MissingFunctionParameterTypehintRule.php | MissingFunctionParameterTypehintRule.processNode | public function processNode(Node $node, Scope $scope): array
{
$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name->name), $scope);
$messages = [];
foreach (ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getParameters() as $parameterReflection) {
$message = $this->checkFunctionParameter($functionReflection, $parameterReflection);
if ($message === null) {
continue;
}
$messages[] = $message;
}
return $messages;
} | php | public function processNode(Node $node, Scope $scope): array
{
$functionReflection = $this->broker->getCustomFunction(new Node\Name($node->name->name), $scope);
$messages = [];
foreach (ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getParameters() as $parameterReflection) {
$message = $this->checkFunctionParameter($functionReflection, $parameterReflection);
if ($message === null) {
continue;
}
$messages[] = $message;
}
return $messages;
} | [
"public",
"function",
"processNode",
"(",
"Node",
"$",
"node",
",",
"Scope",
"$",
"scope",
")",
":",
"array",
"{",
"$",
"functionReflection",
"=",
"$",
"this",
"->",
"broker",
"->",
"getCustomFunction",
"(",
"new",
"Node",
"\\",
"Name",
"(",
"$",
"node",... | @param \PhpParser\Node\Stmt\Function_ $node
@param \PHPStan\Analyser\Scope $scope
@return string[] errors | [
"@param",
"\\",
"PhpParser",
"\\",
"Node",
"\\",
"Stmt",
"\\",
"Function_",
"$node",
"@param",
"\\",
"PHPStan",
"\\",
"Analyser",
"\\",
"Scope",
"$scope"
] | train | https://github.com/phpstan/phpstan-strict-rules/blob/12e0191f1edee174283d682a986c7b586206d3db/src/Rules/Functions/MissingFunctionParameterTypehintRule.php#L35-L51 |
phpstan/phpstan-strict-rules | src/Rules/Methods/MissingMethodParameterTypehintRule.php | MissingMethodParameterTypehintRule.processNode | public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
}
$methodReflection = $scope->getClassReflection()->getNativeMethod($node->name->name);
$messages = [];
foreach (ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getParameters() as $parameterReflection) {
$message = $this->checkMethodParameter($methodReflection, $parameterReflection);
if ($message === null) {
continue;
}
/** @var string $message */
$message = $message;
$messages[] = $message;
}
return $messages;
} | php | public function processNode(Node $node, Scope $scope): array
{
if (!$scope->isInClass()) {
throw new \PHPStan\ShouldNotHappenException();
}
$methodReflection = $scope->getClassReflection()->getNativeMethod($node->name->name);
$messages = [];
foreach (ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getParameters() as $parameterReflection) {
$message = $this->checkMethodParameter($methodReflection, $parameterReflection);
if ($message === null) {
continue;
}
/** @var string $message */
$message = $message;
$messages[] = $message;
}
return $messages;
} | [
"public",
"function",
"processNode",
"(",
"Node",
"$",
"node",
",",
"Scope",
"$",
"scope",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"scope",
"->",
"isInClass",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"PHPStan",
"\\",
"ShouldNotHappenException",
"... | @param \PhpParser\Node\Stmt\ClassMethod $node
@param \PHPStan\Analyser\Scope $scope
@return string[] errors | [
"@param",
"\\",
"PhpParser",
"\\",
"Node",
"\\",
"Stmt",
"\\",
"ClassMethod",
"$node",
"@param",
"\\",
"PHPStan",
"\\",
"Analyser",
"\\",
"Scope",
"$scope"
] | train | https://github.com/phpstan/phpstan-strict-rules/blob/12e0191f1edee174283d682a986c7b586206d3db/src/Rules/Methods/MissingMethodParameterTypehintRule.php#L29-L52 |
hassankhan/config | src/Parser/Json.php | Json.parseFile | public function parseFile($filename)
{
$data = json_decode(file_get_contents($filename), true);
return (array)$this->parse($data, $filename);
} | php | public function parseFile($filename)
{
$data = json_decode(file_get_contents($filename), true);
return (array)$this->parse($data, $filename);
} | [
"public",
"function",
"parseFile",
"(",
"$",
"filename",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"file_get_contents",
"(",
"$",
"filename",
")",
",",
"true",
")",
";",
"return",
"(",
"array",
")",
"$",
"this",
"->",
"parse",
"(",
"$",
"data",
... | {@inheritDoc}
Parses an JSON file as an array
@throws ParseException If there is an error parsing the JSON file | [
"{",
"@inheritDoc",
"}",
"Parses",
"an",
"JSON",
"file",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Json.php#L25-L30 |
hassankhan/config | src/Parser/Json.php | Json.parse | protected function parse($data = null, $filename = null)
{
if (json_last_error() !== JSON_ERROR_NONE) {
$error_message = 'Syntax error';
if (function_exists('json_last_error_msg')) {
$error_message = json_last_error_msg();
}
$error = [
'message' => $error_message,
'type' => json_last_error(),
'file' => $filename,
];
throw new ParseException($error);
}
return $data;
} | php | protected function parse($data = null, $filename = null)
{
if (json_last_error() !== JSON_ERROR_NONE) {
$error_message = 'Syntax error';
if (function_exists('json_last_error_msg')) {
$error_message = json_last_error_msg();
}
$error = [
'message' => $error_message,
'type' => json_last_error(),
'file' => $filename,
];
throw new ParseException($error);
}
return $data;
} | [
"protected",
"function",
"parse",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"filename",
"=",
"null",
")",
"{",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"JSON_ERROR_NONE",
")",
"{",
"$",
"error_message",
"=",
"'Syntax error'",
";",
"if",
"(",
"functi... | Completes parsing of JSON data
@param array $data
@param string $filename
@return array|null
@throws ParseException If there is an error parsing the JSON data | [
"Completes",
"parsing",
"of",
"JSON",
"data"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Json.php#L54-L72 |
hassankhan/config | src/Parser/Xml.php | Xml.parseFile | public function parseFile($filename)
{
libxml_use_internal_errors(true);
$data = simplexml_load_file($filename, null, LIBXML_NOERROR);
return (array)$this->parse($data, $filename);
} | php | public function parseFile($filename)
{
libxml_use_internal_errors(true);
$data = simplexml_load_file($filename, null, LIBXML_NOERROR);
return (array)$this->parse($data, $filename);
} | [
"public",
"function",
"parseFile",
"(",
"$",
"filename",
")",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"data",
"=",
"simplexml_load_file",
"(",
"$",
"filename",
",",
"null",
",",
"LIBXML_NOERROR",
")",
";",
"return",
"(",
"array",
")",
... | {@inheritDoc}
Parses an XML file as an array
@throws ParseException If there is an error parsing the XML file | [
"{",
"@inheritDoc",
"}",
"Parses",
"an",
"XML",
"file",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Xml.php#L25-L31 |
hassankhan/config | src/Parser/Xml.php | Xml.parseString | public function parseString($config)
{
libxml_use_internal_errors(true);
$data = simplexml_load_string($config, null, LIBXML_NOERROR);
return (array)$this->parse($data);
} | php | public function parseString($config)
{
libxml_use_internal_errors(true);
$data = simplexml_load_string($config, null, LIBXML_NOERROR);
return (array)$this->parse($data);
} | [
"public",
"function",
"parseString",
"(",
"$",
"config",
")",
"{",
"libxml_use_internal_errors",
"(",
"true",
")",
";",
"$",
"data",
"=",
"simplexml_load_string",
"(",
"$",
"config",
",",
"null",
",",
"LIBXML_NOERROR",
")",
";",
"return",
"(",
"array",
")",
... | {@inheritDoc}
Parses an XML string as an array
@throws ParseException If there is an error parsing the XML string | [
"{",
"@inheritDoc",
"}",
"Parses",
"an",
"XML",
"string",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Xml.php#L39-L44 |
hassankhan/config | src/Parser/Xml.php | Xml.parse | protected function parse($data = null, $filename = null)
{
if ($data === false) {
$errors = libxml_get_errors();
$latestError = array_pop($errors);
$error = [
'message' => $latestError->message,
'type' => $latestError->level,
'code' => $latestError->code,
'file' => $filename,
'line' => $latestError->line,
];
throw new ParseException($error);
}
$data = json_decode(json_encode($data), true);
return $data;
} | php | protected function parse($data = null, $filename = null)
{
if ($data === false) {
$errors = libxml_get_errors();
$latestError = array_pop($errors);
$error = [
'message' => $latestError->message,
'type' => $latestError->level,
'code' => $latestError->code,
'file' => $filename,
'line' => $latestError->line,
];
throw new ParseException($error);
}
$data = json_decode(json_encode($data), true);
return $data;
} | [
"protected",
"function",
"parse",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"filename",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"$",
"errors",
"=",
"libxml_get_errors",
"(",
")",
";",
"$",
"latestError",
"=",
"array_po... | Completes parsing of XML data
@param array $data
@param string $filename
@return array|null
@throws ParseException If there is an error parsing the XML data | [
"Completes",
"parsing",
"of",
"XML",
"data"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Xml.php#L56-L74 |
hassankhan/config | src/Parser/Ini.php | Ini.parseFile | public function parseFile($filename)
{
$data = @parse_ini_file($filename, true);
return $this->parse($data, $filename);
} | php | public function parseFile($filename)
{
$data = @parse_ini_file($filename, true);
return $this->parse($data, $filename);
} | [
"public",
"function",
"parseFile",
"(",
"$",
"filename",
")",
"{",
"$",
"data",
"=",
"@",
"parse_ini_file",
"(",
"$",
"filename",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"parse",
"(",
"$",
"data",
",",
"$",
"filename",
")",
";",
"}"
] | {@inheritDoc}
Parses an INI file as an array
@throws ParseException If there is an error parsing the INI file | [
"{",
"@inheritDoc",
"}",
"Parses",
"an",
"INI",
"file",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Ini.php#L25-L29 |
hassankhan/config | src/Parser/Ini.php | Ini.parse | protected function parse($data = null, $filename = null)
{
if (!$data) {
$error = error_get_last();
// Parse functions may return NULL but set no error if the string contains no parsable data
if (!is_array($error)) {
$error["message"] = "No parsable content in data.";
}
$error["file"] = $filename;
// if string contains no parsable data, no error is set, resulting in any previous error
// persisting in error_get_last(). in php 7 this can be addressed with error_clear_last()
if (function_exists("error_clear_last")) {
error_clear_last();
}
throw new ParseException($error);
}
return $this->expandDottedKey($data);
} | php | protected function parse($data = null, $filename = null)
{
if (!$data) {
$error = error_get_last();
// Parse functions may return NULL but set no error if the string contains no parsable data
if (!is_array($error)) {
$error["message"] = "No parsable content in data.";
}
$error["file"] = $filename;
// if string contains no parsable data, no error is set, resulting in any previous error
// persisting in error_get_last(). in php 7 this can be addressed with error_clear_last()
if (function_exists("error_clear_last")) {
error_clear_last();
}
throw new ParseException($error);
}
return $this->expandDottedKey($data);
} | [
"protected",
"function",
"parse",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"filename",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"$",
"error",
"=",
"error_get_last",
"(",
")",
";",
"// Parse functions may return NULL but set no error if t... | Completes parsing of INI data
@param array $data
@param strring $filename
@throws ParseException If there is an error parsing the INI data | [
"Completes",
"parsing",
"of",
"INI",
"data"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Ini.php#L51-L73 |
hassankhan/config | src/AbstractConfig.php | AbstractConfig.set | public function set($key, $value)
{
$segs = explode('.', $key);
$root = &$this->data;
$cacheKey = '';
// Look for the key, creating nested keys if needed
while ($part = array_shift($segs)) {
if ($cacheKey != '') {
$cacheKey .= '.';
}
$cacheKey .= $part;
if (!isset($root[$part]) && count($segs)) {
$root[$part] = [];
}
$root = &$root[$part];
//Unset all old nested cache
if (isset($this->cache[$cacheKey])) {
unset($this->cache[$cacheKey]);
}
//Unset all old nested cache in case of array
if (count($segs) == 0) {
foreach ($this->cache as $cacheLocalKey => $cacheValue) {
if (substr($cacheLocalKey, 0, strlen($cacheKey)) === $cacheKey) {
unset($this->cache[$cacheLocalKey]);
}
}
}
}
// Assign value at target node
$this->cache[$key] = $root = $value;
} | php | public function set($key, $value)
{
$segs = explode('.', $key);
$root = &$this->data;
$cacheKey = '';
// Look for the key, creating nested keys if needed
while ($part = array_shift($segs)) {
if ($cacheKey != '') {
$cacheKey .= '.';
}
$cacheKey .= $part;
if (!isset($root[$part]) && count($segs)) {
$root[$part] = [];
}
$root = &$root[$part];
//Unset all old nested cache
if (isset($this->cache[$cacheKey])) {
unset($this->cache[$cacheKey]);
}
//Unset all old nested cache in case of array
if (count($segs) == 0) {
foreach ($this->cache as $cacheLocalKey => $cacheValue) {
if (substr($cacheLocalKey, 0, strlen($cacheKey)) === $cacheKey) {
unset($this->cache[$cacheLocalKey]);
}
}
}
}
// Assign value at target node
$this->cache[$key] = $root = $value;
} | [
"public",
"function",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"segs",
"=",
"explode",
"(",
"'.'",
",",
"$",
"key",
")",
";",
"$",
"root",
"=",
"&",
"$",
"this",
"->",
"data",
";",
"$",
"cacheKey",
"=",
"''",
";",
"// Look for ... | {@inheritDoc} | [
"{"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/AbstractConfig.php#L75-L109 |
hassankhan/config | src/AbstractConfig.php | AbstractConfig.has | public function has($key)
{
// Check if already cached
if (isset($this->cache[$key])) {
return true;
}
$segments = explode('.', $key);
$root = $this->data;
// nested case
foreach ($segments as $segment) {
if (array_key_exists($segment, $root)) {
$root = $root[$segment];
continue;
} else {
return false;
}
}
// Set cache for the given key
$this->cache[$key] = $root;
return true;
} | php | public function has($key)
{
// Check if already cached
if (isset($this->cache[$key])) {
return true;
}
$segments = explode('.', $key);
$root = $this->data;
// nested case
foreach ($segments as $segment) {
if (array_key_exists($segment, $root)) {
$root = $root[$segment];
continue;
} else {
return false;
}
}
// Set cache for the given key
$this->cache[$key] = $root;
return true;
} | [
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"// Check if already cached",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"cache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"segments",
"=",
"explode",
"(",
"'.'",
... | {@inheritDoc} | [
"{"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/AbstractConfig.php#L114-L138 |
hassankhan/config | src/AbstractConfig.php | AbstractConfig.merge | public function merge(ConfigInterface $config)
{
$this->data = array_replace_recursive($this->data, $config->all());
return $this;
} | php | public function merge(ConfigInterface $config)
{
$this->data = array_replace_recursive($this->data, $config->all());
return $this;
} | [
"public",
"function",
"merge",
"(",
"ConfigInterface",
"$",
"config",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"array_replace_recursive",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"config",
"->",
"all",
"(",
")",
")",
";",
"return",
"$",
"this",
";",
... | Merge config from another instance
@param ConfigInterface $config
@return ConfigInterface | [
"Merge",
"config",
"from",
"another",
"instance"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/AbstractConfig.php#L146-L150 |
hassankhan/config | src/Config.php | Config.loadFromFile | protected function loadFromFile($path, ParserInterface $parser = null)
{
$paths = $this->getValidPath($path);
$this->data = [];
foreach ($paths as $path) {
if ($parser === null) {
// Get file information
$info = pathinfo($path);
$parts = explode('.', $info['basename']);
$extension = array_pop($parts);
// Skip the `dist` extension
if ($extension === 'dist') {
$extension = array_pop($parts);
}
// Get file parser
$parser = $this->getParser($extension);
// Try to load file
$this->data = array_replace_recursive($this->data, $parser->parseFile($path));
// Clean parser
$parser = null;
} else {
// Try to load file using specified parser
$this->data = array_replace_recursive($this->data, $parser->parseFile($path));
}
}
} | php | protected function loadFromFile($path, ParserInterface $parser = null)
{
$paths = $this->getValidPath($path);
$this->data = [];
foreach ($paths as $path) {
if ($parser === null) {
// Get file information
$info = pathinfo($path);
$parts = explode('.', $info['basename']);
$extension = array_pop($parts);
// Skip the `dist` extension
if ($extension === 'dist') {
$extension = array_pop($parts);
}
// Get file parser
$parser = $this->getParser($extension);
// Try to load file
$this->data = array_replace_recursive($this->data, $parser->parseFile($path));
// Clean parser
$parser = null;
} else {
// Try to load file using specified parser
$this->data = array_replace_recursive($this->data, $parser->parseFile($path));
}
}
} | [
"protected",
"function",
"loadFromFile",
"(",
"$",
"path",
",",
"ParserInterface",
"$",
"parser",
"=",
"null",
")",
"{",
"$",
"paths",
"=",
"$",
"this",
"->",
"getValidPath",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"data",
"=",
"[",
"]",
";",
... | Loads configuration from file.
@param string|array $path Filenames or directories with configuration
@param ParserInterface $parser Configuration parser
@throws EmptyDirectoryException If `$path` is an empty directory | [
"Loads",
"configuration",
"from",
"file",
"."
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Config.php#L76-L106 |
hassankhan/config | src/Config.php | Config.loadFromString | protected function loadFromString($configuration, ParserInterface $parser)
{
$this->data = [];
// Try to parse string
$this->data = array_replace_recursive($this->data, $parser->parseString($configuration));
} | php | protected function loadFromString($configuration, ParserInterface $parser)
{
$this->data = [];
// Try to parse string
$this->data = array_replace_recursive($this->data, $parser->parseString($configuration));
} | [
"protected",
"function",
"loadFromString",
"(",
"$",
"configuration",
",",
"ParserInterface",
"$",
"parser",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"[",
"]",
";",
"// Try to parse string",
"$",
"this",
"->",
"data",
"=",
"array_replace_recursive",
"(",
"$",... | Loads configuration from string.
@param string $configuration String with configuration
@param ParserInterface $parser Configuration parser | [
"Loads",
"configuration",
"from",
"string",
"."
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Config.php#L114-L120 |
hassankhan/config | src/Config.php | Config.getParser | protected function getParser($extension)
{
foreach ($this->supportedParsers as $parser) {
if (in_array($extension, $parser::getSupportedExtensions())) {
return new $parser();
}
}
// If none exist, then throw an exception
throw new UnsupportedFormatException('Unsupported configuration format');
} | php | protected function getParser($extension)
{
foreach ($this->supportedParsers as $parser) {
if (in_array($extension, $parser::getSupportedExtensions())) {
return new $parser();
}
}
// If none exist, then throw an exception
throw new UnsupportedFormatException('Unsupported configuration format');
} | [
"protected",
"function",
"getParser",
"(",
"$",
"extension",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"supportedParsers",
"as",
"$",
"parser",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"extension",
",",
"$",
"parser",
"::",
"getSupportedExtensions",
"... | Gets a parser for a given file extension.
@param string $extension
@return Noodlehaus\Parser\ParserInterface
@throws UnsupportedFormatException If `$extension` is an unsupported file format | [
"Gets",
"a",
"parser",
"for",
"a",
"given",
"file",
"extension",
"."
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Config.php#L131-L141 |
hassankhan/config | src/Parser/Php.php | Php.parseFile | public function parseFile($filename)
{
// Run the fileEval the string, if it throws an exception, rethrow it
try {
$data = require $filename;
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'PHP file threw an exception',
'exception' => $exception,
]
);
}
// Complete parsing
return (array)$this->parse($data, $filename);
} | php | public function parseFile($filename)
{
// Run the fileEval the string, if it throws an exception, rethrow it
try {
$data = require $filename;
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'PHP file threw an exception',
'exception' => $exception,
]
);
}
// Complete parsing
return (array)$this->parse($data, $filename);
} | [
"public",
"function",
"parseFile",
"(",
"$",
"filename",
")",
"{",
"// Run the fileEval the string, if it throws an exception, rethrow it",
"try",
"{",
"$",
"data",
"=",
"require",
"$",
"filename",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"... | {@inheritDoc}
Loads a PHP file and gets its' contents as an array
@throws ParseException If the PHP file throws an exception
@throws UnsupportedFormatException If the PHP file does not return an array | [
"{",
"@inheritDoc",
"}",
"Loads",
"a",
"PHP",
"file",
"and",
"gets",
"its",
"contents",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Php.php#L28-L44 |
hassankhan/config | src/Parser/Php.php | Php.parseString | public function parseString($config)
{
// Handle PHP start tag
$config = trim($config);
if (substr($config, 0, 2) === '<?') {
$config = '?>' . $config;
}
// Eval the string, if it throws an exception, rethrow it
try {
$data = $this->isolate($config);
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'PHP string threw an exception',
'exception' => $exception,
]
);
}
// Complete parsing
return (array)$this->parse($data);
} | php | public function parseString($config)
{
// Handle PHP start tag
$config = trim($config);
if (substr($config, 0, 2) === '<?') {
$config = '?>' . $config;
}
// Eval the string, if it throws an exception, rethrow it
try {
$data = $this->isolate($config);
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'PHP string threw an exception',
'exception' => $exception,
]
);
}
// Complete parsing
return (array)$this->parse($data);
} | [
"public",
"function",
"parseString",
"(",
"$",
"config",
")",
"{",
"// Handle PHP start tag",
"$",
"config",
"=",
"trim",
"(",
"$",
"config",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"config",
",",
"0",
",",
"2",
")",
"===",
"'<?'",
")",
"{",
"$",
... | {@inheritDoc}
Loads a PHP string and gets its' contents as an array
@throws ParseException If the PHP string throws an exception
@throws UnsupportedFormatException If the PHP string does not return an array | [
"{",
"@inheritDoc",
"}",
"Loads",
"a",
"PHP",
"string",
"and",
"gets",
"its",
"contents",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Php.php#L53-L75 |
hassankhan/config | src/Parser/Php.php | Php.parse | protected function parse($data = null, $filename = null)
{
// If we have a callable, run it and expect an array back
if (is_callable($data)) {
$data = call_user_func($data);
}
// Check for array, if its anything else, throw an exception
if (!is_array($data)) {
throw new UnsupportedFormatException('PHP data does not return an array');
}
return $data;
} | php | protected function parse($data = null, $filename = null)
{
// If we have a callable, run it and expect an array back
if (is_callable($data)) {
$data = call_user_func($data);
}
// Check for array, if its anything else, throw an exception
if (!is_array($data)) {
throw new UnsupportedFormatException('PHP data does not return an array');
}
return $data;
} | [
"protected",
"function",
"parse",
"(",
"$",
"data",
"=",
"null",
",",
"$",
"filename",
"=",
"null",
")",
"{",
"// If we have a callable, run it and expect an array back",
"if",
"(",
"is_callable",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"call_user_f... | Completes parsing of PHP data
@param array $data
@param string $filename
@return array|null
@throws UnsupportedFormatException | [
"Completes",
"parsing",
"of",
"PHP",
"data"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Php.php#L86-L99 |
hassankhan/config | src/Parser/Yaml.php | Yaml.parseFile | public function parseFile($filename)
{
try {
$data = YamlParser::parseFile($filename, YamlParser::PARSE_CONSTANT);
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'Error parsing YAML file',
'exception' => $exception,
]
);
}
return (array)$this->parse($data);
} | php | public function parseFile($filename)
{
try {
$data = YamlParser::parseFile($filename, YamlParser::PARSE_CONSTANT);
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'Error parsing YAML file',
'exception' => $exception,
]
);
}
return (array)$this->parse($data);
} | [
"public",
"function",
"parseFile",
"(",
"$",
"filename",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"YamlParser",
"::",
"parseFile",
"(",
"$",
"filename",
",",
"YamlParser",
"::",
"PARSE_CONSTANT",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
... | {@inheritDoc}
Loads a YAML/YML file as an array
@throws ParseException If there is an error parsing the YAML file | [
"{",
"@inheritDoc",
"}",
"Loads",
"a",
"YAML",
"/",
"YML",
"file",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Yaml.php#L27-L41 |
hassankhan/config | src/Parser/Yaml.php | Yaml.parseString | public function parseString($config)
{
try {
$data = YamlParser::parse($config, YamlParser::PARSE_CONSTANT);
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'Error parsing YAML string',
'exception' => $exception,
]
);
}
return (array)$this->parse($data);
} | php | public function parseString($config)
{
try {
$data = YamlParser::parse($config, YamlParser::PARSE_CONSTANT);
} catch (Exception $exception) {
throw new ParseException(
[
'message' => 'Error parsing YAML string',
'exception' => $exception,
]
);
}
return (array)$this->parse($data);
} | [
"public",
"function",
"parseString",
"(",
"$",
"config",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"YamlParser",
"::",
"parse",
"(",
"$",
"config",
",",
"YamlParser",
"::",
"PARSE_CONSTANT",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
... | {@inheritDoc}
Loads a YAML/YML string as an array
@throws ParseException If If there is an error parsing the YAML string | [
"{",
"@inheritDoc",
"}",
"Loads",
"a",
"YAML",
"/",
"YML",
"string",
"as",
"an",
"array"
] | train | https://github.com/hassankhan/config/blob/d30cdc72d37a592e856e9f1b62e29a03b049d785/src/Parser/Yaml.php#L49-L63 |
bernardphp/bernard | src/Driver/Doctrine/Command/AbstractCommand.php | AbstractCommand.execute | public function execute(InputInterface $input, OutputInterface $output)
{
$schema = new Schema();
MessagesSchema::create($schema);
$sync = $this->getSynchronizer($this->getHelper('connection')->getConnection());
if ($input->getOption('dump-sql')) {
$output->writeln(implode(';'.PHP_EOL, $this->getSql($sync, $schema)).';');
return;
}
$output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.'.PHP_EOL);
$output->writeln('Applying database schema changes...');
$this->applySql($sync, $schema);
$output->writeln('Schema changes applied successfully!');
} | php | public function execute(InputInterface $input, OutputInterface $output)
{
$schema = new Schema();
MessagesSchema::create($schema);
$sync = $this->getSynchronizer($this->getHelper('connection')->getConnection());
if ($input->getOption('dump-sql')) {
$output->writeln(implode(';'.PHP_EOL, $this->getSql($sync, $schema)).';');
return;
}
$output->writeln('<comment>ATTENTION</comment>: This operation should not be executed in a production environment.'.PHP_EOL);
$output->writeln('Applying database schema changes...');
$this->applySql($sync, $schema);
$output->writeln('Schema changes applied successfully!');
} | [
"public",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"schema",
"=",
"new",
"Schema",
"(",
")",
";",
"MessagesSchema",
"::",
"create",
"(",
"$",
"schema",
")",
";",
"$",
"sync",
"=",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/Doctrine/Command/AbstractCommand.php#L32-L48 |
bernardphp/bernard | src/Driver/Pheanstalk/Driver.php | Driver.popMessage | public function popMessage($queueName, $duration = 5)
{
if ($job = $this->pheanstalk->reserveFromTube($queueName, $duration)) {
return [$job->getData(), $job];
}
return [null, null];
} | php | public function popMessage($queueName, $duration = 5)
{
if ($job = $this->pheanstalk->reserveFromTube($queueName, $duration)) {
return [$job->getData(), $job];
}
return [null, null];
} | [
"public",
"function",
"popMessage",
"(",
"$",
"queueName",
",",
"$",
"duration",
"=",
"5",
")",
"{",
"if",
"(",
"$",
"job",
"=",
"$",
"this",
"->",
"pheanstalk",
"->",
"reserveFromTube",
"(",
"$",
"queueName",
",",
"$",
"duration",
")",
")",
"{",
"re... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/Pheanstalk/Driver.php#L58-L65 |
bernardphp/bernard | src/Driver/MongoDB/Driver.php | Driver.createQueue | public function createQueue($queueName)
{
$data = ['_id' => (string) $queueName];
$this->queues->update($data, $data, ['upsert' => true]);
} | php | public function createQueue($queueName)
{
$data = ['_id' => (string) $queueName];
$this->queues->update($data, $data, ['upsert' => true]);
} | [
"public",
"function",
"createQueue",
"(",
"$",
"queueName",
")",
"{",
"$",
"data",
"=",
"[",
"'_id'",
"=>",
"(",
"string",
")",
"$",
"queueName",
"]",
";",
"$",
"this",
"->",
"queues",
"->",
"update",
"(",
"$",
"data",
",",
"$",
"data",
",",
"[",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/MongoDB/Driver.php#L38-L43 |
bernardphp/bernard | src/Driver/MongoDB/Driver.php | Driver.pushMessage | public function pushMessage($queueName, $message)
{
$data = [
'queue' => (string) $queueName,
'message' => (string) $message,
'sentAt' => new MongoDate(),
'visible' => true,
];
$this->messages->insert($data);
} | php | public function pushMessage($queueName, $message)
{
$data = [
'queue' => (string) $queueName,
'message' => (string) $message,
'sentAt' => new MongoDate(),
'visible' => true,
];
$this->messages->insert($data);
} | [
"public",
"function",
"pushMessage",
"(",
"$",
"queueName",
",",
"$",
"message",
")",
"{",
"$",
"data",
"=",
"[",
"'queue'",
"=>",
"(",
"string",
")",
"$",
"queueName",
",",
"'message'",
"=>",
"(",
"string",
")",
"$",
"message",
",",
"'sentAt'",
"=>",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/MongoDB/Driver.php#L59-L69 |
bernardphp/bernard | src/Driver/MongoDB/Driver.php | Driver.popMessage | public function popMessage($queueName, $duration = 5)
{
$runtime = microtime(true) + $duration;
while (microtime(true) < $runtime) {
$result = $this->messages->findAndModify(
['queue' => (string) $queueName, 'visible' => true],
['$set' => ['visible' => false]],
['message' => 1],
['sort' => ['sentAt' => 1]]
);
if ($result) {
return [(string) $result['message'], (string) $result['_id']];
}
usleep(10000);
}
return [null, null];
} | php | public function popMessage($queueName, $duration = 5)
{
$runtime = microtime(true) + $duration;
while (microtime(true) < $runtime) {
$result = $this->messages->findAndModify(
['queue' => (string) $queueName, 'visible' => true],
['$set' => ['visible' => false]],
['message' => 1],
['sort' => ['sentAt' => 1]]
);
if ($result) {
return [(string) $result['message'], (string) $result['_id']];
}
usleep(10000);
}
return [null, null];
} | [
"public",
"function",
"popMessage",
"(",
"$",
"queueName",
",",
"$",
"duration",
"=",
"5",
")",
"{",
"$",
"runtime",
"=",
"microtime",
"(",
"true",
")",
"+",
"$",
"duration",
";",
"while",
"(",
"microtime",
"(",
"true",
")",
"<",
"$",
"runtime",
")",... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/MongoDB/Driver.php#L74-L94 |
bernardphp/bernard | src/Driver/MongoDB/Driver.php | Driver.acknowledgeMessage | public function acknowledgeMessage($queueName, $receipt)
{
$this->messages->remove([
'_id' => new MongoId((string) $receipt),
'queue' => (string) $queueName,
]);
} | php | public function acknowledgeMessage($queueName, $receipt)
{
$this->messages->remove([
'_id' => new MongoId((string) $receipt),
'queue' => (string) $queueName,
]);
} | [
"public",
"function",
"acknowledgeMessage",
"(",
"$",
"queueName",
",",
"$",
"receipt",
")",
"{",
"$",
"this",
"->",
"messages",
"->",
"remove",
"(",
"[",
"'_id'",
"=>",
"new",
"MongoId",
"(",
"(",
"string",
")",
"$",
"receipt",
")",
",",
"'queue'",
"=... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/MongoDB/Driver.php#L99-L105 |
bernardphp/bernard | src/Driver/MongoDB/Driver.php | Driver.peekQueue | public function peekQueue($queueName, $index = 0, $limit = 20)
{
$query = ['queue' => (string) $queueName, 'visible' => true];
$fields = ['_id' => 0, 'message' => 1];
$cursor = $this->messages
->find($query, $fields)
->sort(['sentAt' => 1])
->limit($limit)
->skip($index)
;
$mapper = function ($result) {
return (string) $result['message'];
};
return array_map($mapper, iterator_to_array($cursor, false));
} | php | public function peekQueue($queueName, $index = 0, $limit = 20)
{
$query = ['queue' => (string) $queueName, 'visible' => true];
$fields = ['_id' => 0, 'message' => 1];
$cursor = $this->messages
->find($query, $fields)
->sort(['sentAt' => 1])
->limit($limit)
->skip($index)
;
$mapper = function ($result) {
return (string) $result['message'];
};
return array_map($mapper, iterator_to_array($cursor, false));
} | [
"public",
"function",
"peekQueue",
"(",
"$",
"queueName",
",",
"$",
"index",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
")",
"{",
"$",
"query",
"=",
"[",
"'queue'",
"=>",
"(",
"string",
")",
"$",
"queueName",
",",
"'visible'",
"=>",
"true",
"]",
";",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/MongoDB/Driver.php#L110-L127 |
bernardphp/bernard | src/Driver/MongoDB/Driver.php | Driver.removeQueue | public function removeQueue($queueName)
{
$this->queues->remove(['_id' => $queueName]);
$this->messages->remove(['queue' => (string) $queueName]);
} | php | public function removeQueue($queueName)
{
$this->queues->remove(['_id' => $queueName]);
$this->messages->remove(['queue' => (string) $queueName]);
} | [
"public",
"function",
"removeQueue",
"(",
"$",
"queueName",
")",
"{",
"$",
"this",
"->",
"queues",
"->",
"remove",
"(",
"[",
"'_id'",
"=>",
"$",
"queueName",
"]",
")",
";",
"$",
"this",
"->",
"messages",
"->",
"remove",
"(",
"[",
"'queue'",
"=>",
"("... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/MongoDB/Driver.php#L132-L136 |
bernardphp/bernard | src/Command/ConsumeCommand.php | ConsumeCommand.execute | public function execute(InputInterface $input, OutputInterface $output)
{
$queue = $this->getQueue($input->getArgument('queue'));
$this->consumer->consume($queue, $input->getOptions());
} | php | public function execute(InputInterface $input, OutputInterface $output)
{
$queue = $this->getQueue($input->getArgument('queue'));
$this->consumer->consume($queue, $input->getOptions());
} | [
"public",
"function",
"execute",
"(",
"InputInterface",
"$",
"input",
",",
"OutputInterface",
"$",
"output",
")",
"{",
"$",
"queue",
"=",
"$",
"this",
"->",
"getQueue",
"(",
"$",
"input",
"->",
"getArgument",
"(",
"'queue'",
")",
")",
";",
"$",
"this",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Command/ConsumeCommand.php#L48-L53 |
bernardphp/bernard | src/Command/ConsumeCommand.php | ConsumeCommand.getQueue | protected function getQueue($queue)
{
if (is_array($queue)) {
if (count($queue) > 1) {
$queues = array_map([$this->queues, 'create'], $queue);
return new RoundRobinQueue($queues);
}
$queue = $queue[0];
}
return $this->queues->create($queue);
} | php | protected function getQueue($queue)
{
if (is_array($queue)) {
if (count($queue) > 1) {
$queues = array_map([$this->queues, 'create'], $queue);
return new RoundRobinQueue($queues);
}
$queue = $queue[0];
}
return $this->queues->create($queue);
} | [
"protected",
"function",
"getQueue",
"(",
"$",
"queue",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"queue",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"queue",
")",
">",
"1",
")",
"{",
"$",
"queues",
"=",
"array_map",
"(",
"[",
"$",
"this",
"... | @param array|string $queue
@return Queue | [
"@param",
"array|string",
"$queue"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Command/ConsumeCommand.php#L60-L73 |
bernardphp/bernard | src/Driver/InMemory/Driver.php | Driver.countMessages | public function countMessages($queueName)
{
if (array_key_exists($queueName, $this->queues)) {
return count($this->queues[$queueName]);
}
return 0;
} | php | public function countMessages($queueName)
{
if (array_key_exists($queueName, $this->queues)) {
return count($this->queues[$queueName]);
}
return 0;
} | [
"public",
"function",
"countMessages",
"(",
"$",
"queueName",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"queueName",
",",
"$",
"this",
"->",
"queues",
")",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"queues",
"[",
"$",
"queueName",
"... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/InMemory/Driver.php#L35-L42 |
bernardphp/bernard | src/Driver/InMemory/Driver.php | Driver.popMessage | public function popMessage($queueName, $duration = 5)
{
if (!array_key_exists($queueName, $this->queues) || count($this->queues[$queueName]) < 1) {
return [null, null];
}
return [array_shift($this->queues[$queueName]), null];
} | php | public function popMessage($queueName, $duration = 5)
{
if (!array_key_exists($queueName, $this->queues) || count($this->queues[$queueName]) < 1) {
return [null, null];
}
return [array_shift($this->queues[$queueName]), null];
} | [
"public",
"function",
"popMessage",
"(",
"$",
"queueName",
",",
"$",
"duration",
"=",
"5",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"queueName",
",",
"$",
"this",
"->",
"queues",
")",
"||",
"count",
"(",
"$",
"this",
"->",
"queues",
"[... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/InMemory/Driver.php#L55-L62 |
bernardphp/bernard | src/Driver/InMemory/Driver.php | Driver.peekQueue | public function peekQueue($queueName, $index = 0, $limit = 20)
{
if (array_key_exists($queueName, $this->queues)) {
return array_slice($this->queues[$queueName], $index, $limit);
}
return null;
} | php | public function peekQueue($queueName, $index = 0, $limit = 20)
{
if (array_key_exists($queueName, $this->queues)) {
return array_slice($this->queues[$queueName], $index, $limit);
}
return null;
} | [
"public",
"function",
"peekQueue",
"(",
"$",
"queueName",
",",
"$",
"index",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"queueName",
",",
"$",
"this",
"->",
"queues",
")",
")",
"{",
"return",
"array_sli... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/InMemory/Driver.php#L75-L82 |
bernardphp/bernard | src/Router/ContainerReceiverResolver.php | ContainerReceiverResolver.resolve | public function resolve($receiver, Envelope $envelope)
{
try {
$receiver = $this->container->get($receiver);
} catch (NotFoundExceptionInterface $e) {
return null;
}
return parent::resolve($receiver, $envelope);
} | php | public function resolve($receiver, Envelope $envelope)
{
try {
$receiver = $this->container->get($receiver);
} catch (NotFoundExceptionInterface $e) {
return null;
}
return parent::resolve($receiver, $envelope);
} | [
"public",
"function",
"resolve",
"(",
"$",
"receiver",
",",
"Envelope",
"$",
"envelope",
")",
"{",
"try",
"{",
"$",
"receiver",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"receiver",
")",
";",
"}",
"catch",
"(",
"NotFoundExceptionInterfa... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Router/ContainerReceiverResolver.php#L35-L44 |
bernardphp/bernard | src/Router/SimpleReceiverResolver.php | SimpleReceiverResolver.resolve | public function resolve($receiver, Envelope $envelope)
{
if (null === $receiver) {
return null;
}
if ($receiver instanceof Receiver) {
return $receiver;
}
if (is_callable($receiver) == false) {
$receiver = [$receiver, lcfirst($envelope->getName())];
}
// Receiver is still not a callable which means it's not a valid receiver.
if (is_callable($receiver) == false) {
return null;
}
return new Receiver\CallableReceiver($receiver);
} | php | public function resolve($receiver, Envelope $envelope)
{
if (null === $receiver) {
return null;
}
if ($receiver instanceof Receiver) {
return $receiver;
}
if (is_callable($receiver) == false) {
$receiver = [$receiver, lcfirst($envelope->getName())];
}
// Receiver is still not a callable which means it's not a valid receiver.
if (is_callable($receiver) == false) {
return null;
}
return new Receiver\CallableReceiver($receiver);
} | [
"public",
"function",
"resolve",
"(",
"$",
"receiver",
",",
"Envelope",
"$",
"envelope",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"receiver",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"receiver",
"instanceof",
"Receiver",
")",
"{",
"return"... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Router/SimpleReceiverResolver.php#L24-L44 |
bernardphp/bernard | src/Normalizer/EnvelopeNormalizer.php | EnvelopeNormalizer.normalize | public function normalize($object, $format = null, array $context = [])
{
return [
'class' => $object->getClass(),
'timestamp' => $object->getTimestamp(),
'message' => $this->aggregate->normalize($object->getMessage()),
];
} | php | public function normalize($object, $format = null, array $context = [])
{
return [
'class' => $object->getClass(),
'timestamp' => $object->getTimestamp(),
'message' => $this->aggregate->normalize($object->getMessage()),
];
} | [
"public",
"function",
"normalize",
"(",
"$",
"object",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"return",
"[",
"'class'",
"=>",
"$",
"object",
"->",
"getClass",
"(",
")",
",",
"'timestamp'",
"=>",
"$",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Normalizer/EnvelopeNormalizer.php#L30-L37 |
bernardphp/bernard | src/Normalizer/EnvelopeNormalizer.php | EnvelopeNormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = [])
{
try {
Assertion::choicesNotEmpty($data, ['message', 'class', 'timestamp']);
Assertion::classExists($data['class']);
} catch (AssertionFailedException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
$envelope = new Envelope($this->aggregate->denormalize($data['message'], $data['class']));
$this->forcePropertyValue($envelope, 'class', $data['class']);
$this->forcePropertyValue($envelope, 'timestamp', $data['timestamp']);
return $envelope;
} | php | public function denormalize($data, $class, $format = null, array $context = [])
{
try {
Assertion::choicesNotEmpty($data, ['message', 'class', 'timestamp']);
Assertion::classExists($data['class']);
} catch (AssertionFailedException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
$envelope = new Envelope($this->aggregate->denormalize($data['message'], $data['class']));
$this->forcePropertyValue($envelope, 'class', $data['class']);
$this->forcePropertyValue($envelope, 'timestamp', $data['timestamp']);
return $envelope;
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"Assertion",
"::",
"choicesNotEmpty",
"(",
"$",
"data",
",",
"[",
"'message'... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Normalizer/EnvelopeNormalizer.php#L42-L57 |
bernardphp/bernard | src/Driver/PrefetchMessageCache.php | PrefetchMessageCache.pop | public function pop($queueName)
{
$cache = $this->get($queueName);
if (!$cache->isEmpty()) {
return $cache->dequeue();
}
} | php | public function pop($queueName)
{
$cache = $this->get($queueName);
if (!$cache->isEmpty()) {
return $cache->dequeue();
}
} | [
"public",
"function",
"pop",
"(",
"$",
"queueName",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"queueName",
")",
";",
"if",
"(",
"!",
"$",
"cache",
"->",
"isEmpty",
"(",
")",
")",
"{",
"return",
"$",
"cache",
"->",
"dequeue"... | Get the next message in line. Or nothing if there is no more
in the cache.
@param string $queueName
@return array|null | [
"Get",
"the",
"next",
"message",
"in",
"line",
".",
"Or",
"nothing",
"if",
"there",
"is",
"no",
"more",
"in",
"the",
"cache",
"."
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/PrefetchMessageCache.php#L29-L36 |
bernardphp/bernard | src/Driver/PrefetchMessageCache.php | PrefetchMessageCache.get | protected function get($queueName)
{
if (isset($this->caches[$queueName])) {
return $this->caches[$queueName];
}
return $this->caches[$queueName] = new \SplQueue();
} | php | protected function get($queueName)
{
if (isset($this->caches[$queueName])) {
return $this->caches[$queueName];
}
return $this->caches[$queueName] = new \SplQueue();
} | [
"protected",
"function",
"get",
"(",
"$",
"queueName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"caches",
"[",
"$",
"queueName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"caches",
"[",
"$",
"queueName",
"]",
";",
"}",
"return",... | Create the queue cache internally if it doesn't yet exists.
@param string $queueName
@return \SplQueue | [
"Create",
"the",
"queue",
"cache",
"internally",
"if",
"it",
"doesn",
"t",
"yet",
"exists",
"."
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/PrefetchMessageCache.php#L45-L52 |
bernardphp/bernard | src/Normalizer/PlainMessageNormalizer.php | PlainMessageNormalizer.denormalize | public function denormalize($data, $class, $format = null, array $context = [])
{
try {
Assertion::notEmptyKey($data, 'name');
Assertion::keyExists($data, 'arguments');
Assertion::isArray($data['arguments']);
} catch (AssertionFailedException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
return new PlainMessage($data['name'], $data['arguments']);
} | php | public function denormalize($data, $class, $format = null, array $context = [])
{
try {
Assertion::notEmptyKey($data, 'name');
Assertion::keyExists($data, 'arguments');
Assertion::isArray($data['arguments']);
} catch (AssertionFailedException $e) {
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
}
return new PlainMessage($data['name'], $data['arguments']);
} | [
"public",
"function",
"denormalize",
"(",
"$",
"data",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"Assertion",
"::",
"notEmptyKey",
"(",
"$",
"data",
",",
"'name'",
")",
";... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Normalizer/PlainMessageNormalizer.php#L28-L39 |
bernardphp/bernard | src/Driver/PhpRedis/Driver.php | Driver.pushMessage | public function pushMessage($queueName, $message)
{
$this->redis->rpush($this->resolveKey($queueName), $message);
} | php | public function pushMessage($queueName, $message)
{
$this->redis->rpush($this->resolveKey($queueName), $message);
} | [
"public",
"function",
"pushMessage",
"(",
"$",
"queueName",
",",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"rpush",
"(",
"$",
"this",
"->",
"resolveKey",
"(",
"$",
"queueName",
")",
",",
"$",
"message",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/PhpRedis/Driver.php#L51-L54 |
bernardphp/bernard | src/Driver/PhpRedis/Driver.php | Driver.peekQueue | public function peekQueue($queueName, $index = 0, $limit = 20)
{
$limit += $index - 1;
return $this->redis->lRange($this->resolveKey($queueName), $index, $limit);
} | php | public function peekQueue($queueName, $index = 0, $limit = 20)
{
$limit += $index - 1;
return $this->redis->lRange($this->resolveKey($queueName), $index, $limit);
} | [
"public",
"function",
"peekQueue",
"(",
"$",
"queueName",
",",
"$",
"index",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
")",
"{",
"$",
"limit",
"+=",
"$",
"index",
"-",
"1",
";",
"return",
"$",
"this",
"->",
"redis",
"->",
"lRange",
"(",
"$",
"this"... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/PhpRedis/Driver.php#L77-L82 |
bernardphp/bernard | src/Driver/PhpRedis/Driver.php | Driver.removeQueue | public function removeQueue($queueName)
{
$this->redis->sRem('queues', $queueName);
$this->redis->del($this->resolveKey($queueName));
} | php | public function removeQueue($queueName)
{
$this->redis->sRem('queues', $queueName);
$this->redis->del($this->resolveKey($queueName));
} | [
"public",
"function",
"removeQueue",
"(",
"$",
"queueName",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"sRem",
"(",
"'queues'",
",",
"$",
"queueName",
")",
";",
"$",
"this",
"->",
"redis",
"->",
"del",
"(",
"$",
"this",
"->",
"resolveKey",
"(",
"$",... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/PhpRedis/Driver.php#L94-L98 |
bernardphp/bernard | src/Router/ClassNameRouter.php | ClassNameRouter.get | protected function get($name)
{
foreach ($this->receivers as $key => $receiver) {
if (is_a($name, $key, true)) {
return $receiver;
}
}
return null;
} | php | protected function get($name)
{
foreach ($this->receivers as $key => $receiver) {
if (is_a($name, $key, true)) {
return $receiver;
}
}
return null;
} | [
"protected",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"receivers",
"as",
"$",
"key",
"=>",
"$",
"receiver",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"name",
",",
"$",
"key",
",",
"true",
")",
")",
"{",
"re... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Router/ClassNameRouter.php#L16-L25 |
bernardphp/bernard | src/QueueFactory/PersistentFactory.php | PersistentFactory.create | public function create($queueName)
{
if (isset($this->queues[$queueName])) {
return $this->queues[$queueName];
}
$queue = new PersistentQueue($queueName, $this->driver, $this->serializer);
return $this->queues[$queueName] = $queue;
} | php | public function create($queueName)
{
if (isset($this->queues[$queueName])) {
return $this->queues[$queueName];
}
$queue = new PersistentQueue($queueName, $this->driver, $this->serializer);
return $this->queues[$queueName] = $queue;
} | [
"public",
"function",
"create",
"(",
"$",
"queueName",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"queues",
"[",
"$",
"queueName",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"queues",
"[",
"$",
"queueName",
"]",
";",
"}",
"$",
"q... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/QueueFactory/PersistentFactory.php#L33-L42 |
bernardphp/bernard | src/QueueFactory/PersistentFactory.php | PersistentFactory.exists | public function exists($queueName)
{
return isset($this->queues[$queueName]) ?: in_array($queueName, $this->driver->listQueues());
} | php | public function exists($queueName)
{
return isset($this->queues[$queueName]) ?: in_array($queueName, $this->driver->listQueues());
} | [
"public",
"function",
"exists",
"(",
"$",
"queueName",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"queues",
"[",
"$",
"queueName",
"]",
")",
"?",
":",
"in_array",
"(",
"$",
"queueName",
",",
"$",
"this",
"->",
"driver",
"->",
"listQueues",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/QueueFactory/PersistentFactory.php#L58-L61 |
bernardphp/bernard | src/Queue/PersistentQueue.php | PersistentQueue.enqueue | public function enqueue(Envelope $envelope)
{
$this->errorIfClosed();
$this->driver->pushMessage($this->name, $this->serializer->serialize($envelope));
} | php | public function enqueue(Envelope $envelope)
{
$this->errorIfClosed();
$this->driver->pushMessage($this->name, $this->serializer->serialize($envelope));
} | [
"public",
"function",
"enqueue",
"(",
"Envelope",
"$",
"envelope",
")",
"{",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"$",
"this",
"->",
"driver",
"->",
"pushMessage",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"this",
"->",
"serializer",
"->"... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/PersistentQueue.php#L64-L69 |
bernardphp/bernard | src/Queue/PersistentQueue.php | PersistentQueue.acknowledge | public function acknowledge(Envelope $envelope)
{
$this->errorIfClosed();
if ($this->receipts->contains($envelope)) {
$this->driver->acknowledgeMessage($this->name, $this->receipts[$envelope]);
$this->receipts->detach($envelope);
}
} | php | public function acknowledge(Envelope $envelope)
{
$this->errorIfClosed();
if ($this->receipts->contains($envelope)) {
$this->driver->acknowledgeMessage($this->name, $this->receipts[$envelope]);
$this->receipts->detach($envelope);
}
} | [
"public",
"function",
"acknowledge",
"(",
"Envelope",
"$",
"envelope",
")",
"{",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"receipts",
"->",
"contains",
"(",
"$",
"envelope",
")",
")",
"{",
"$",
"this",
"->",
"d... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/PersistentQueue.php#L74-L83 |
bernardphp/bernard | src/Queue/PersistentQueue.php | PersistentQueue.dequeue | public function dequeue($duration = 5)
{
$this->errorIfClosed();
list($serialized, $receipt) = $this->driver->popMessage($this->name, $duration);
if ($serialized) {
$envelope = $this->serializer->unserialize($serialized);
$this->receipts->attach($envelope, $receipt);
return $envelope;
}
} | php | public function dequeue($duration = 5)
{
$this->errorIfClosed();
list($serialized, $receipt) = $this->driver->popMessage($this->name, $duration);
if ($serialized) {
$envelope = $this->serializer->unserialize($serialized);
$this->receipts->attach($envelope, $receipt);
return $envelope;
}
} | [
"public",
"function",
"dequeue",
"(",
"$",
"duration",
"=",
"5",
")",
"{",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"list",
"(",
"$",
"serialized",
",",
"$",
"receipt",
")",
"=",
"$",
"this",
"->",
"driver",
"->",
"popMessage",
"(",
"$",
... | {@inheritdoc}
@param int $duration number of seconds to keep polling for messages | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/PersistentQueue.php#L90-L103 |
bernardphp/bernard | src/Queue/PersistentQueue.php | PersistentQueue.peek | public function peek($index = 0, $limit = 20)
{
$this->errorIfClosed();
$messages = $this->driver->peekQueue($this->name, $index, $limit);
return array_map([$this->serializer, 'unserialize'], $messages);
} | php | public function peek($index = 0, $limit = 20)
{
$this->errorIfClosed();
$messages = $this->driver->peekQueue($this->name, $index, $limit);
return array_map([$this->serializer, 'unserialize'], $messages);
} | [
"public",
"function",
"peek",
"(",
"$",
"index",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
")",
"{",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"$",
"messages",
"=",
"$",
"this",
"->",
"driver",
"->",
"peekQueue",
"(",
"$",
"this",
"->",
"n... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/PersistentQueue.php#L108-L115 |
bernardphp/bernard | src/Driver/Amqp/Driver.php | Driver.createQueue | public function createQueue($queueName)
{
$channel = $this->getChannel();
$channel->exchange_declare($this->exchange, 'direct', false, true, false);
$channel->queue_declare($queueName, false, true, false, false);
$channel->queue_bind($queueName, $this->exchange, $queueName);
} | php | public function createQueue($queueName)
{
$channel = $this->getChannel();
$channel->exchange_declare($this->exchange, 'direct', false, true, false);
$channel->queue_declare($queueName, false, true, false, false);
$channel->queue_bind($queueName, $this->exchange, $queueName);
} | [
"public",
"function",
"createQueue",
"(",
"$",
"queueName",
")",
"{",
"$",
"channel",
"=",
"$",
"this",
"->",
"getChannel",
"(",
")",
";",
"$",
"channel",
"->",
"exchange_declare",
"(",
"$",
"this",
"->",
"exchange",
",",
"'direct'",
",",
"false",
",",
... | Create a queue.
@param string $queueName | [
"Create",
"a",
"queue",
"."
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/Amqp/Driver.php#L57-L63 |
bernardphp/bernard | src/Driver/Amqp/Driver.php | Driver.countMessages | public function countMessages($queueName)
{
list(, $messageCount) = $this->getChannel()->queue_declare($queueName, true);
return $messageCount;
} | php | public function countMessages($queueName)
{
list(, $messageCount) = $this->getChannel()->queue_declare($queueName, true);
return $messageCount;
} | [
"public",
"function",
"countMessages",
"(",
"$",
"queueName",
")",
"{",
"list",
"(",
",",
"$",
"messageCount",
")",
"=",
"$",
"this",
"->",
"getChannel",
"(",
")",
"->",
"queue_declare",
"(",
"$",
"queueName",
",",
"true",
")",
";",
"return",
"$",
"mes... | Count the number of messages in queue. This can be a approximately number.
@param string $queueName
@return int | [
"Count",
"the",
"number",
"of",
"messages",
"in",
"queue",
".",
"This",
"can",
"be",
"a",
"approximately",
"number",
"."
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/Amqp/Driver.php#L72-L77 |
bernardphp/bernard | src/Driver/Amqp/Driver.php | Driver.pushMessage | public function pushMessage($queueName, $message)
{
$amqpMessage = new AMQPMessage($message, $this->defaultMessageParams);
$this->getChannel()->basic_publish($amqpMessage, $this->exchange, $queueName);
} | php | public function pushMessage($queueName, $message)
{
$amqpMessage = new AMQPMessage($message, $this->defaultMessageParams);
$this->getChannel()->basic_publish($amqpMessage, $this->exchange, $queueName);
} | [
"public",
"function",
"pushMessage",
"(",
"$",
"queueName",
",",
"$",
"message",
")",
"{",
"$",
"amqpMessage",
"=",
"new",
"AMQPMessage",
"(",
"$",
"message",
",",
"$",
"this",
"->",
"defaultMessageParams",
")",
";",
"$",
"this",
"->",
"getChannel",
"(",
... | Insert a message at the top of the queue.
@param string $queueName
@param string $message | [
"Insert",
"a",
"message",
"at",
"the",
"top",
"of",
"the",
"queue",
"."
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/Amqp/Driver.php#L85-L89 |
bernardphp/bernard | src/Driver/Amqp/Driver.php | Driver.popMessage | public function popMessage($queueName, $duration = 5)
{
$runtime = microtime(true) + $duration;
while (microtime(true) < $runtime) {
$message = $this->getChannel()->basic_get($queueName);
if ($message) {
return [$message->body, $message->get('delivery_tag')];
}
// sleep for 10 ms to prevent hammering CPU
usleep(10000);
}
return [null, null];
} | php | public function popMessage($queueName, $duration = 5)
{
$runtime = microtime(true) + $duration;
while (microtime(true) < $runtime) {
$message = $this->getChannel()->basic_get($queueName);
if ($message) {
return [$message->body, $message->get('delivery_tag')];
}
// sleep for 10 ms to prevent hammering CPU
usleep(10000);
}
return [null, null];
} | [
"public",
"function",
"popMessage",
"(",
"$",
"queueName",
",",
"$",
"duration",
"=",
"5",
")",
"{",
"$",
"runtime",
"=",
"microtime",
"(",
"true",
")",
"+",
"$",
"duration",
";",
"while",
"(",
"microtime",
"(",
"true",
")",
"<",
"$",
"runtime",
")",... | Remove the next message in line. And if no message is available
wait $duration seconds.
@param string $queueName
@param int $duration
@return array An array like array($message, $receipt); | [
"Remove",
"the",
"next",
"message",
"in",
"line",
".",
"And",
"if",
"no",
"message",
"is",
"available",
"wait",
"$duration",
"seconds",
"."
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/Amqp/Driver.php#L100-L116 |
bernardphp/bernard | src/Router/ReceiverMapRouter.php | ReceiverMapRouter.route | public function route(Envelope $envelope)
{
$receiver = $this->get($this->getName($envelope));
$receiver = $this->receiverResolver->resolve($receiver, $envelope);
if (null === $receiver) {
throw new ReceiverNotFoundException(sprintf('No receiver found with name "%s".', $envelope->getName()));
}
return $receiver;
} | php | public function route(Envelope $envelope)
{
$receiver = $this->get($this->getName($envelope));
$receiver = $this->receiverResolver->resolve($receiver, $envelope);
if (null === $receiver) {
throw new ReceiverNotFoundException(sprintf('No receiver found with name "%s".', $envelope->getName()));
}
return $receiver;
} | [
"public",
"function",
"route",
"(",
"Envelope",
"$",
"envelope",
")",
"{",
"$",
"receiver",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"this",
"->",
"getName",
"(",
"$",
"envelope",
")",
")",
";",
"$",
"receiver",
"=",
"$",
"this",
"->",
"receiverResol... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Router/ReceiverMapRouter.php#L51-L61 |
bernardphp/bernard | src/Router/ReceiverMapRouter.php | ReceiverMapRouter.get | protected function get($name)
{
return isset($this->receivers[$name]) ? $this->receivers[$name] : null;
} | php | protected function get($name)
{
return isset($this->receivers[$name]) ? $this->receivers[$name] : null;
} | [
"protected",
"function",
"get",
"(",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"receivers",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"receivers",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | @param string $name
@return mixed | [
"@param",
"string",
"$name"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Router/ReceiverMapRouter.php#L68-L71 |
bernardphp/bernard | src/Queue/InMemoryQueue.php | InMemoryQueue.peek | public function peek($index = 0, $limit = 20)
{
$this->errorIfClosed();
$envelopes = [];
$queue = clone $this->queue;
$key = 0;
while ($queue->count() && count($envelopes) < $limit && $envelope = $queue->dequeue()) {
if ($key++ < $index) {
continue;
}
$envelopes[] = $envelope;
}
return $envelopes;
} | php | public function peek($index = 0, $limit = 20)
{
$this->errorIfClosed();
$envelopes = [];
$queue = clone $this->queue;
$key = 0;
while ($queue->count() && count($envelopes) < $limit && $envelope = $queue->dequeue()) {
if ($key++ < $index) {
continue;
}
$envelopes[] = $envelope;
}
return $envelopes;
} | [
"public",
"function",
"peek",
"(",
"$",
"index",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
")",
"{",
"$",
"this",
"->",
"errorIfClosed",
"(",
")",
";",
"$",
"envelopes",
"=",
"[",
"]",
";",
"$",
"queue",
"=",
"clone",
"$",
"this",
"->",
"queue",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/InMemoryQueue.php#L64-L81 |
bernardphp/bernard | src/Serializer.php | Serializer.unserialize | public function unserialize($contents)
{
$data = json_decode($contents, true);
return $this->aggregate->denormalize($data, 'Bernard\Envelope');
} | php | public function unserialize($contents)
{
$data = json_decode($contents, true);
return $this->aggregate->denormalize($data, 'Bernard\Envelope');
} | [
"public",
"function",
"unserialize",
"(",
"$",
"contents",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"contents",
",",
"true",
")",
";",
"return",
"$",
"this",
"->",
"aggregate",
"->",
"denormalize",
"(",
"$",
"data",
",",
"'Bernard\\Envelope'",
... | @param string $contents
@return Envelope | [
"@param",
"string",
"$contents"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Serializer.php#L34-L39 |
bernardphp/bernard | src/Queue/RoundRobinQueue.php | RoundRobinQueue.enqueue | public function enqueue(Envelope $envelope)
{
$this->verifyEnvelope($envelope);
$this->queues[$envelope->getName()]->enqueue($envelope);
} | php | public function enqueue(Envelope $envelope)
{
$this->verifyEnvelope($envelope);
$this->queues[$envelope->getName()]->enqueue($envelope);
} | [
"public",
"function",
"enqueue",
"(",
"Envelope",
"$",
"envelope",
")",
"{",
"$",
"this",
"->",
"verifyEnvelope",
"(",
"$",
"envelope",
")",
";",
"$",
"this",
"->",
"queues",
"[",
"$",
"envelope",
"->",
"getName",
"(",
")",
"]",
"->",
"enqueue",
"(",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/RoundRobinQueue.php#L40-L45 |
bernardphp/bernard | src/Queue/RoundRobinQueue.php | RoundRobinQueue.dequeue | public function dequeue()
{
$envelope = null;
$checked = [];
while (count($checked) < count($this->queues)) {
$queue = current($this->queues);
$envelope = $queue->dequeue();
if (false === next($this->queues)) {
reset($this->queues);
}
if ($envelope) {
$this->envelopes->attach($envelope, $queue);
break;
} else {
$checked[] = $queue;
}
}
return $envelope;
} | php | public function dequeue()
{
$envelope = null;
$checked = [];
while (count($checked) < count($this->queues)) {
$queue = current($this->queues);
$envelope = $queue->dequeue();
if (false === next($this->queues)) {
reset($this->queues);
}
if ($envelope) {
$this->envelopes->attach($envelope, $queue);
break;
} else {
$checked[] = $queue;
}
}
return $envelope;
} | [
"public",
"function",
"dequeue",
"(",
")",
"{",
"$",
"envelope",
"=",
"null",
";",
"$",
"checked",
"=",
"[",
"]",
";",
"while",
"(",
"count",
"(",
"$",
"checked",
")",
"<",
"count",
"(",
"$",
"this",
"->",
"queues",
")",
")",
"{",
"$",
"queue",
... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/RoundRobinQueue.php#L50-L70 |
bernardphp/bernard | src/Queue/RoundRobinQueue.php | RoundRobinQueue.close | public function close()
{
if ($this->closed) {
return;
}
foreach ($this->queues as $queue) {
$queue->close();
}
$this->closed = true;
} | php | public function close()
{
if ($this->closed) {
return;
}
foreach ($this->queues as $queue) {
$queue->close();
}
$this->closed = true;
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"closed",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"queues",
"as",
"$",
"queue",
")",
"{",
"$",
"queue",
"->",
"close",
"(",
")",
";",
"}",
"$",... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/RoundRobinQueue.php#L75-L86 |
bernardphp/bernard | src/Queue/RoundRobinQueue.php | RoundRobinQueue.peek | public function peek($index = 0, $limit = 20)
{
$it = new \InfiniteIterator(new \ArrayIterator($this->queues));
$envelopes = $drained = $indexes = [];
foreach (array_keys($this->queues) as $name) {
$indexes[$name] = 0;
}
$shift = 0;
$key = key($this->queues);
for ($it->rewind(); $it->key() != $key; $it->next()) {
// noop
}
while (count($envelopes) < $limit && count($drained) < $it->count()) {
$queue = $it->current();
$name = $it->key();
if ($peeked = $queue->peek($indexes[$name], 1)) {
if ($shift < $index) {
++$shift;
++$indexes[$name];
} else {
$envelopes[] = array_shift($peeked);
}
} else {
$drained[$name] = true;
}
$it->next();
}
return $envelopes;
} | php | public function peek($index = 0, $limit = 20)
{
$it = new \InfiniteIterator(new \ArrayIterator($this->queues));
$envelopes = $drained = $indexes = [];
foreach (array_keys($this->queues) as $name) {
$indexes[$name] = 0;
}
$shift = 0;
$key = key($this->queues);
for ($it->rewind(); $it->key() != $key; $it->next()) {
// noop
}
while (count($envelopes) < $limit && count($drained) < $it->count()) {
$queue = $it->current();
$name = $it->key();
if ($peeked = $queue->peek($indexes[$name], 1)) {
if ($shift < $index) {
++$shift;
++$indexes[$name];
} else {
$envelopes[] = array_shift($peeked);
}
} else {
$drained[$name] = true;
}
$it->next();
}
return $envelopes;
} | [
"public",
"function",
"peek",
"(",
"$",
"index",
"=",
"0",
",",
"$",
"limit",
"=",
"20",
")",
"{",
"$",
"it",
"=",
"new",
"\\",
"InfiniteIterator",
"(",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"this",
"->",
"queues",
")",
")",
";",
"$",
"envelopes"... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/RoundRobinQueue.php#L91-L122 |
bernardphp/bernard | src/Queue/RoundRobinQueue.php | RoundRobinQueue.acknowledge | public function acknowledge(Envelope $envelope)
{
if (!$this->envelopes->contains($envelope)) {
throw new \DomainException(
'Unrecognized queue specified: '.$envelope->getName()
);
}
$queue = $this->envelopes[$envelope];
$queue->acknowledge($envelope);
$this->envelopes->detach($envelope);
} | php | public function acknowledge(Envelope $envelope)
{
if (!$this->envelopes->contains($envelope)) {
throw new \DomainException(
'Unrecognized queue specified: '.$envelope->getName()
);
}
$queue = $this->envelopes[$envelope];
$queue->acknowledge($envelope);
$this->envelopes->detach($envelope);
} | [
"public",
"function",
"acknowledge",
"(",
"Envelope",
"$",
"envelope",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"envelopes",
"->",
"contains",
"(",
"$",
"envelope",
")",
")",
"{",
"throw",
"new",
"\\",
"DomainException",
"(",
"'Unrecognized queue specifi... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Queue/RoundRobinQueue.php#L127-L138 |
bernardphp/bernard | src/EventListener/ErrorLogSubscriber.php | ErrorLogSubscriber.format | protected function format(Envelope $envelope, $exception)
{
if ($exception instanceof Exception || $exception instanceof Throwable) {
$replacements = [
'{class}' => get_class($exception),
'{message}' => $exception->getMessage(),
'{envelope}' => $envelope->getName(),
];
return strtr('[bernard] caught exception {class}::{message} while processing {envelope}.', $replacements);
}
$replacements = [
'{type}' => is_object($exception) ? get_class($exception) : gettype($exception),
'{envelope}' => $envelope->getName(),
];
return strtr('[bernard] caught unknown error type {type} while processing {envelope}.', $replacements);
} | php | protected function format(Envelope $envelope, $exception)
{
if ($exception instanceof Exception || $exception instanceof Throwable) {
$replacements = [
'{class}' => get_class($exception),
'{message}' => $exception->getMessage(),
'{envelope}' => $envelope->getName(),
];
return strtr('[bernard] caught exception {class}::{message} while processing {envelope}.', $replacements);
}
$replacements = [
'{type}' => is_object($exception) ? get_class($exception) : gettype($exception),
'{envelope}' => $envelope->getName(),
];
return strtr('[bernard] caught unknown error type {type} while processing {envelope}.', $replacements);
} | [
"protected",
"function",
"format",
"(",
"Envelope",
"$",
"envelope",
",",
"$",
"exception",
")",
"{",
"if",
"(",
"$",
"exception",
"instanceof",
"Exception",
"||",
"$",
"exception",
"instanceof",
"Throwable",
")",
"{",
"$",
"replacements",
"=",
"[",
"'{class... | @param Envelope $envelope
@param mixed $exception
@return string | [
"@param",
"Envelope",
"$envelope",
"@param",
"mixed",
"$exception"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/EventListener/ErrorLogSubscriber.php#L27-L45 |
bernardphp/bernard | src/Driver/FlatFile/Driver.php | Driver.listQueues | public function listQueues()
{
$it = new \FilesystemIterator($this->baseDirectory, \FilesystemIterator::SKIP_DOTS);
$queues = [];
foreach ($it as $file) {
if (!$file->isDir()) {
continue;
}
array_push($queues, $file->getBasename());
}
return $queues;
} | php | public function listQueues()
{
$it = new \FilesystemIterator($this->baseDirectory, \FilesystemIterator::SKIP_DOTS);
$queues = [];
foreach ($it as $file) {
if (!$file->isDir()) {
continue;
}
array_push($queues, $file->getBasename());
}
return $queues;
} | [
"public",
"function",
"listQueues",
"(",
")",
"{",
"$",
"it",
"=",
"new",
"\\",
"FilesystemIterator",
"(",
"$",
"this",
"->",
"baseDirectory",
",",
"\\",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
";",
"$",
"queues",
"=",
"[",
"]",
";",
"foreach",
"("... | {@inheritdoc} | [
"{"
] | train | https://github.com/bernardphp/bernard/blob/3ff88921bea87186d1baffc93708dd7aee4e963e/src/Driver/FlatFile/Driver.php#L30-L45 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.