承接 selective/array-reader 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

selective/array-reader

最新稳定版本:2.2.0

Composer 安装命令:

composer require selective/array-reader

包简介

A strictly typed array reader

README 文档

README

A strictly typed array reader for PHP.

Latest Version on Packagist Software License Build Status Total Downloads

Requirements

  • PHP 8.1 - 8.4

Installation

composer require selective/array-reader

Usage

You can use the ArrayReader to read single values from a multidimensional array by passing the path to one of the get{type}() and find{type}() methods.

Each get*() / find*() method takes a default value as second argument. If the path cannot be found in the original array, the default is used as return value.

A get*() method returns only the declared return type. If the default value is not given and the element cannot be found, an exception is thrown.

A find*() method returns only the declared return type or null. No exception is thrown if the element cannot be found.

<?php

use Selective\ArrayReader\ArrayReader;

$arrayReader = new ArrayReader([
    'key1' => [
        'key2' => [
            'key3' => 'value1',
        ]
    ]
]);

// Output: value1
echo $arrayReader->getString('key1.key2.key3');

Better Code Quality

Converting complex data with simple PHP works by using a lot of type casting and if conditions etc. This leads to very high cyclomatic complexity and nesting depth, and thus poor "code rating".

Before: Conditions: 10, Paths: 512, CRAP Score: 10

Click to expand!

After: Conditions: 1, Paths: 1, CRAP Score: 1

Click to expand!

Similar libraries

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 65.9k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 2
  • Forks: 5
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-10-19