Skip to content

Commit

Permalink
Add api documentations
Browse files Browse the repository at this point in the history
  • Loading branch information
cable8mm committed Mar 9, 2024
1 parent 1efbfbf commit f7f95ef
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,6 @@ $RECYCLE.BIN/
# End of https://www.toptal.com/developers/gitignore/api/composer,macos,windows,visualstudiocode

composer.lock
/build
/cache
/doctum.php
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# Array Flatten

[![Tests](https://github.com/cable8mm/array-flatten/actions/workflows/tests.yml/badge.svg)](https://github.com/cable8mm/array-flatten/actions/workflows/tests.yml)
[![PHP Linting (Pint)](https://github.com/cable8mm/array-flatten/actions/workflows/coding-style-php.yml/badge.svg)](https://github.com/cable8mm/array-flatten/actions/workflows/coding-style-php.yml)
[![Latest Stable Version](http://poser.pugx.org/cable8mm/array-flatten/v)](https://packagist.org/packages/cable8mm/array-flatten)
[![Total Downloads](http://poser.pugx.org/cable8mm/array-flatten/downloads)](https://packagist.org/packages/cable8mm/array-flatten)
[![release date](https://img.shields.io/github/release-date/cable8mm/array-flatten)](https://github.com/cable8mm/array-flatten/releases)
![GitHub License](https://img.shields.io/github/license/cable8mm/array-flatten)
[![PHP Version Require](http://poser.pugx.org/cable8mm/array-flatten/require/php)](https://packagist.org/packages/cable8mm/array-flatten)

> Flatten nested arrays.
[![code-style](https://github.com/cable8mm/array-flatten/actions/workflows/code-style.yml/badge.svg)](https://github.com/cable8mm/array-flatten/actions/workflows/code-style.yml)
[![run-tests](https://github.com/cable8mm/array-flatten/actions/workflows/run-tests.yml/badge.svg)](https://github.com/cable8mm/array-flatten/actions/workflows/run-tests.yml)
![Packagist Version](https://img.shields.io/packagist/v/cable8mm/array-flatten)
![Packagist Downloads](https://img.shields.io/packagist/dt/cable8mm/array-flatten)
![Packagist Dependency Version](https://img.shields.io/packagist/dependency-v/cable8mm/array-flatten/php)
![Packagist Stars](https://img.shields.io/packagist/stars/cable8mm/array-flatten)
![Packagist License](https://img.shields.io/packagist/l/cable8mm/array-flatten)

Flatten nested arrays.

We have provided the API Documentation on the web. For more information, please visit https://www.palgle.com/array-flatten/ ❤️

## Installation

Expand Down
10 changes: 4 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,10 @@
"laravel/pint": "^1.0"
},
"scripts": {
"test": [
"./vendor/bin/phpunit"
],
"lint": [
"./vendor/bin/pint"
]
"test": "./vendor/bin/phpunit tests",
"lint": "./vendor/bin/pint",
"inspect": "./vendor/bin/pint --test",
"apidoc": "doctum.phar update doctum.php --output-format=github --no-ansi --no-progress"
},
"minimum-stability": "stable",
"prefer-stable": true
Expand Down
17 changes: 6 additions & 11 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
executionOrder="depends,defects"
beStrictAboutCoverageMetadata="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
cacheResult ="false">
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
testdox="true">
<testsuites>
<testsuite name="default">
<directory>tests</directory>
</testsuite>
</testsuites>

<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
</phpunit>
20 changes: 19 additions & 1 deletion src/array_flatten.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

namespace Cable8mm\ArrayFlatten;

/**
* Flatten nested arrays. * array_flatten([1, [2, [3, [4, [5], 6], 7], 8], 9]); //=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
*
* @param array $array The nested arrays
* @return array The array to flatten
*
* @example array_flatten([1, [2, [3, [4, [5], 6], 7], 8], 9]);
* //=> [1, 2, 3, 4, 5, 6, 7, 8, 9]
*/
function array_flatten(array $array): array
{
$return = [];
Expand All @@ -13,7 +22,16 @@ function array_flatten(array $array): array
return array_raw_unique($return);
}

function array_raw_unique(array $array)
/**
* Extend array_unique() to include null and space values. array_raw_unique([1, 2, 2, null, null, '', '', 9]); //=> [1, 2, null, '', '', 9]
*
* @param array $array The array
* @return array The unique array even if it contains null and space values
*
* @example array_raw_unique([1, 2, 2, null, null, '', '', 9]);
* //=> [1, 2, null, '', '', 9]
*/
function array_raw_unique(array $array): array
{
$out = [];

Expand Down

0 comments on commit f7f95ef

Please sign in to comment.