<commit_before><?php
/**
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE.txt
 * file that was distributed with this source code.
 *
 * Date: 12.02.2016
 * Time: 10:39
 *
 */

namespace Blast\Orm\Data;


trait FilterableTrait
{
    /**
     * Filter data by callback
     *
     * Emulates array_filter behaviour with optional flags ARRAY_FILTER_USE_BOTH for PHP version < 5.6.x
     *
     * Create a callback with key and value parameters and return a boolean.
     *
     * ```
     * FilterableTrait::filter(function($value, $key){
     *  //added to result if value is scalar
     *  return is_scalar($value)
     * });
     * ```
     *
     * @see http://php.net/manual/de/function.array-filter.php
     *
     * @param callable $filter
     * @return array
     */
    public function filter(callable $filter)
    {
        $data = DataHelper::receiveDataFromObject($this);

        if(defined('ARRAY_FILTER_USE_BOTH') && version_compare(PHP_VERSION, '5.6.0') >= 0){
            return array_filter($data, $filter, ARRAY_FILTER_USE_BOTH);
        }

        $results = [];

        //if filter is truthy pass key-value-pair to results
        foreach($data as $key => $value){
            if(call_user_func($filter, $value, $key) == true){
                $results[$key] = $value;
            }
        }

        return $results;
    }
}<commit_msg>Ignore filter fallback from coverage<commit_after><?php
/**
 *
 * (c) <NAME> <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE.txt
 * file that was distributed with this source code.
 *
 * Date: 12.02.2016
 * Time: 10:39
 *
 */

namespace Blast\Orm\Data;


trait FilterableTrait
{
    /**
     * Filter data by callback
     *
     * Emulates array_filter behaviour with optional flags ARRAY_FILTER_USE_BOTH for PHP version < 5.6.x
     *
     * Create a callback with key and value parameters and return a boolean.
     *
     * ```
     * FilterableTrait::filter(function($value, $key){
     *  //added to result if value is scalar
     *  return is_scalar($value)
     * });
     * ```
     *
     * @see http://php.net/manual/de/function.array-filter.php
     *
     * @param callable $filter
     * @return array
     */
    public function filter(callable $filter)
    {
        $data = DataHelper::receiveDataFromObject($this);

        if(defined('ARRAY_FILTER_USE_BOTH') && version_compare(PHP_VERSION, '5.6.0') >= 0){
            return array_filter($data, $filter, ARRAY_FILTER_USE_BOTH);
        }

        //@codeCoverageIgnore
        //this is a fallback for php versions < 5.6.x
        $results = [];

        //if filter is truthy pass key-value-pair to results
        foreach($data as $key => $value){
            if(call_user_func($filter, $value, $key) == true){
                $results[$key] = $value;
            }
        }

        return $results;
        //@codeCoverageIgnore
    }
}
{'fraction_non_alphanumeric': 0.12647554806070826, 'fraction_numerical': 0.012816188870151771, 'mean_word_length': 2.2665198237885464, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2985794', 'n_tokens_mistral': 947, 'n_tokens_neox': 907, 'n_words': 236}