-
Notifications
You must be signed in to change notification settings - Fork 75
[Suggestion] Code split for Array Utility #69
Comments
Addendum: This will also address to issues like: |
This seems like a good idea to me, since I generally require I still want to drop PHP 5 support, especially considering that the array utils API didn't change over the past year, but I'll probably end up in a fighting pit with @weierophinney :-P @gabbydgab there is still a massive issue with your repository though: you didn't import the original commits, which are in fact really important for tracing bugs and for attribution. Also, a benchmark test suite us absolutely necessary from now on (see zendframework/zend-servicemanager#64). |
@Ocramius just copy-pasted it as of the moment, but if you can guide me on how to properly subsplit it from the upstream then I'll redo it. |
@gabbydgab just cloning this repo and using |
In addition to the QA toolkit, here's the output when I try check code quality using PHP Mess Detector
PS: Didn't change anything yet. It's all based on the current upstream. Also I didn't removed yet the Parameter* classes due to this hard dependency. Thoughts, @Ocramius @weierophinney ? |
since athletic/athletic is no longer maintained, shall we use phpbench/phpbench? |
Yep, phpbench FTW.
As for the ccloc, ignore that for now.
…On 7 Jan 2017 03:34, "Gab Amba" ***@***.***> wrote:
since athletic/athletic <https://github.com/polyfractal/athletic> is no
longer maintained, shall we use phpbench/phpbench
<https://github.com/phpbench/phpbench>?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#69 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAJakIGt7gUhzh1grQ26nhlqgBh4XiNDks5rPvnOgaJpZM4Lc-Ku>
.
|
Created concrete classes for IteratorToArray method to be backwards compatible for zend-stdlib:
It resolves ccloc for ArrayUtils::iteratorToArray() method. public static function iteratorToArray($iterator, $recursive = true)
{
if (! is_array($iterator) && ! $iterator instanceof Traversable) {
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object');
}
if (! $recursive) {
return SimpleIterator::toArray($iterator);
}
return RecursiveIterator::toArray($iterator);
} TO DO:
|
Please don't do that - the CCLOC is there due to past benchmarks. If you are doing a split, just do that and add issues for further improvements later. |
The commits are in this repository: https://github.com/php-refactoring/zend-array-utility (develop branch)
I will not touch that in the upstream (zend-stdlib); just want to demonstrate that the created classes (SimpleIterator and RecursiveIterator) can be used on the current logic. Upstream code: ArrayUtils::iteratorToArray() method public static function iteratorToArray($iterator, $recursive = true)
{
if (! is_array($iterator) && ! $iterator instanceof Traversable) {
throw new Exception\InvalidArgumentException(__METHOD__ . ' expects an array or Traversable object');
}
if (! $recursive) {
if (is_array($iterator)) {
return $iterator;
}
return iterator_to_array($iterator);
}
if (method_exists($iterator, 'toArray')) {
return $iterator->toArray();
}
$array = [];
foreach ($iterator as $key => $value) {
if (is_scalar($value)) {
$array[$key] = $value;
continue;
}
if ($value instanceof Traversable) {
$array[$key] = static::iteratorToArray($value, $recursive);
continue;
}
if (is_array($value)) {
$array[$key] = static::iteratorToArray($value, $recursive);
continue;
}
$array[$key] = $value;
}
return $array;
} Will be simplified to use the Iterator classes in the proposed Zend\ArrayUtils package for BC compatibility public static function iteratorToArray($iterator, $recursive = true)
{
if (! $recursive) {
return SimpleIterator::toArray($iterator);
}
return RecursiveIterator::toArray($iterator);
} I'm thinking that, if applied, will set as deprecated method then suggest to use the appropriate array utily (Zend\ArrayUtils) package moving forward. |
Also, I've added some test (from the current ArrayUtilsTest) for RecursiveIteratorTest but there are scenarios that are not fully covered - like Can't find additional specifications on the tests and benchmark. Can you provide some guidance on this matter? @Ocramius |
I've updated the repository and created a release tag (0.1.x) as extracted array utility functions from the current Added initial benchmarks for: PS: sample data for the benchmark is based on the current test data. Optimization and extraction of functionalities will be next. |
Created issue for feature request: Checks if the provided array configuration is cache-able; One of the best practices being taught is to use factories over closures - since closures are not cache-able. practical usage: private function cacheConfig(array $config, $cachedConfigFile)
{
if (!ArrayUtils::isCachable($config)) {
throw new InvalidArgumentException('Cannot cached config from %s; does not return array', $config);
}
// cache the config
} |
This repository has been closed and moved to laminas/laminas-stdlib; a new issue has been opened at laminas/laminas-stdlib#3. |
Looking at some dependency graph for zend components, one way of requiring zend-stdlib is to use the array functions.
Some of these libraries are:
Separating this may have a relevant value to packages that utilizes array functions such as the framework itself since the default configuration is in array.
Ported repository: https://github.com/php-refactoring/zend-array-utility
Pros:
Cons:
To do:
The text was updated successfully, but these errors were encountered: