Skip to content

Commit 71c4e4f

Browse files
committed
initial commit
1 parent d78cce3 commit 71c4e4f

File tree

12 files changed

+261
-1
lines changed

12 files changed

+261
-1
lines changed

.codeclimate.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
engines:
2+
phpcodesniffer:
3+
enabled: true
4+
checks:
5+
Generic Files LineLength TooLong:
6+
enabled: false
7+
Squiz WhiteSpace ControlStructureSpacing SpacingAfterOpen:
8+
enabled: false
9+
phpmd:
10+
enabled: true
11+
ratings:
12+
paths:
13+
- "**.php"
14+
exclude_paths:
15+
- "tests/"

.scrutinizer.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# .scrutinizer.yml
2+
checks:
3+
php:
4+
code_rating: true
5+
duplication: true
6+
7+
filter:
8+
paths: ['src/*']
9+
10+
tools:
11+
php_code_sniffer:
12+
config:
13+
standard: "PSR2"
14+
15+
build:
16+
environment:
17+
php: 7.1
18+
tests:
19+
override:
20+
-
21+
command: '/usr/local/bin/phpunit --coverage-clover=clover.xml'
22+
coverage:
23+
file: 'clover.xml'
24+
format: 'clover'
25+
26+
project_setup:
27+
before:
28+
- wget https://phar.phpunit.de/phpunit.phar
29+
- chmod +x phpunit.phar
30+
- sudo mv phpunit.phar /usr/local/bin/phpunit

.travis.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
language: php
2+
php:
3+
- 7.0
4+
- 7.1
5+
- nightly
6+
7+
matrix:
8+
allow_failures:
9+
- php: nightly
10+
11+
script:
12+
- phpunit

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
# Changelog
3+
4+
All notable changes to this project will be documented in this file.
5+
6+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
7+
and this project adheres to [Semantic Versioning](http://semver.org/).
8+
9+
## [Unrelased][v0.1.0](https://github.com/s3b4stian/linna-array/compare/v0.1.0...master) - 2017-XX-XX
10+
11+
### Added
12+
* `Linna\intArray` for create integer typed arrays.

LICENSE renamed to LICENSE.md

File renamed without changes.

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
# linna-array
1+
![Linna Framework](logo-array.png)
2+
<br/>
3+
<br/>
4+
<br/>
5+
[![Build Status](https://travis-ci.org/s3b4stian/linna-array.svg?branch=master)](https://travis-ci.org/s3b4stian/linna-array)
6+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/s3b4stian/linna-array/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/s3b4stian/linna-array/?branch=master)
7+
[![Code Coverage](https://scrutinizer-ci.com/g/s3b4stian/linna-array/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/s3b4stian/linna-array/?branch=master)
8+
[![StyleCI](https://styleci.io/repos/93407083/shield?branch=master&style=flat)](https://styleci.io/repos/93407083)
9+
10+
## About this package
211
Typed arrays for php

clover.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<coverage generated="1496671919">
3+
<project timestamp="1496671919">
4+
<package name="Linna">
5+
<file name="/home/sebastian/html/linna-array/src/intArray.php">
6+
<class name="intArray" namespace="Linna">
7+
<metrics complexity="4" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="8" elements="10" coveredelements="10"/>
8+
</class>
9+
<line num="27" type="method" name="__construct" visibility="public" complexity="2" crap="2" count="16"/>
10+
<line num="31" type="stmt" count="16"/>
11+
<line num="32" type="stmt" count="7"/>
12+
<line num="36" type="stmt" count="9"/>
13+
<line num="37" type="stmt" count="9"/>
14+
<line num="47" type="method" name="offsetSet" visibility="public" complexity="2" crap="2" count="8"/>
15+
<line num="49" type="stmt" count="8"/>
16+
<line num="50" type="stmt" count="1"/>
17+
<line num="51" type="stmt" count="1"/>
18+
<line num="54" type="stmt" count="7"/>
19+
<metrics loc="56" ncloc="26" classes="1" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="8" elements="10" coveredelements="10"/>
20+
</file>
21+
</package>
22+
<metrics files="1" loc="56" ncloc="26" classes="1" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="8" coveredstatements="8" elements="10" coveredelements="10"/>
23+
</project>
24+
</coverage>

logo-array.png

6.32 KB
Loading

phpunit.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<phpunit colors="true"
2+
bootstrap="tests/bootstrap.php"
3+
verbose="true">
4+
<testsuites>
5+
<testsuite name="Linna Array Test Suite">
6+
<directory suffix="Test.php">tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
<filter>
10+
<whitelist>
11+
<directory suffix=".php">src</directory>
12+
</whitelist>
13+
</filter>
14+
<logging>
15+
<log type="coverage-clover" target="clover.xml"/>
16+
</logging>
17+
</phpunit>

src/intArray.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/**
4+
* Linna Array.
5+
*
6+
* @author Sebastian Rapetti <[email protected]>
7+
* @copyright (c) 2017, Sebastian Rapetti
8+
* @license http://opensource.org/licenses/MIT MIT License
9+
*/
10+
declare(strict_types=1);
11+
12+
namespace Linna;
13+
14+
use ArrayObject;
15+
use TypeError;
16+
/**
17+
* Create an array of integer elements.
18+
*/
19+
class intArray extends ArrayObject
20+
{
21+
/**
22+
* Contructor.
23+
*
24+
* @param array $array
25+
* @throws TypeError
26+
*/
27+
public function __construct(array $array = [])
28+
{
29+
//for not utilize foreach, compare sizes of array
30+
//before and after apply a filter :)
31+
if (count($array) > count(array_filter($array, 'is_int'))){
32+
throw new TypeError('Elements passed to '.__CLASS__.' must be of the type integer');
33+
}
34+
35+
//call parent constructor
36+
parent::__construct($array, 0, 'ArrayIterator');
37+
}
38+
39+
/**
40+
* Array style value assignment.
41+
*
42+
* @param mixed $index
43+
* @param mixed $newval
44+
* @return void
45+
* @throws TypeError If value passed to $newval is not integer
46+
*/
47+
public function offsetSet($index, $newval)
48+
{
49+
if (is_int($newval)) {
50+
parent::offsetSet($index, $newval);
51+
return;
52+
}
53+
54+
throw new TypeError('Elements passed to '.__CLASS__.' must be of the type integer');
55+
}
56+
}

0 commit comments

Comments
 (0)