Skip to content

Commit a053222

Browse files
author
Gonzalo
committed
first commit
0 parents  commit a053222

24 files changed

+2331
-0
lines changed

.gitattributes

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.gitattributes export-ignore
2+
.gitignore export-ignore
3+
.travis.* export-ignore
4+
.archer.* export-ignore
5+
test export-ignore
6+
*.md export-ignore
7+
LICENCE export-ignore
8+
phpcs.xml export-ignore
9+
phpunit.xml export-ignore

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# composer vendor directory
2+
vendor/
3+
4+
#build
5+
build/
6+
7+
# composer
8+
composer.lock

.travis.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# see http://about.travis-ci.org/docs/user/languages/php/ for more hints
2+
# example: https://github.com/travis-ci-examples/php
3+
language: php
4+
5+
php:
6+
# aliased to a recent 7.x version
7+
- '7.0'
8+
# aliased to a recent 7.1.x version
9+
- '7.1'
10+
# aliased to a recent 7.1.x version
11+
- '7.2'
12+
# aliased to a recent hhvm version
13+
#- hhvm
14+
- nightly
15+
16+
# This triggers builds to run on the new TravisCI infrastructure.
17+
# See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/
18+
sudo: false
19+
20+
## Cache composer
21+
cache:
22+
directories:
23+
- $HOME/.composer/cache
24+
25+
matrix:
26+
fast_finish: true # Will finish as soon as a job has failed, or when the only jobs left allow failures.
27+
include:
28+
- php: '7.0'
29+
env:
30+
- 'COMPOSER_FLAGS="--prefer-stable --prefer-lowest"'
31+
32+
# execute any number of scripts before the test run, custom env's are available as variables
33+
before_script:
34+
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist
35+
36+
# omitting "script:" will default to phpunit
37+
script:
38+
- vendor/bin/phpcs --standard=phpcs.xml
39+
- vendor/bin/phpunit --configuration phpunit.xml --coverage-text
40+
- vendor/bin/phpunit --configuration phpunit.xml --coverage-clover=coverage.xml
41+
42+
after_success:
43+
- bash <(curl -s https://codecov.io/bash)

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Change Log
2+
============
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/en/1.0.0/)
7+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
8+
as it's described in the [Contributing Guide](CONTRIBUTING.md).
9+
10+
# Proposals
11+
12+
We do not give estimated times for completion on `Accepted` Proposals.
13+
14+
- [Accepted][Accepted]
15+
- [Rejected][Rejected]
16+
17+
---
18+
## [v1.0.0][Unreleased] - Unreleased
19+
20+
`INIT`
21+
22+
<!-- References -->
23+
24+
[Accepted]: https://github.com/Triun/PHP-Longest-Common-Substring/labels/Accepted
25+
[Rejected]: https://github.com/Triun/PHP-Longest-Common-Substring/labels/Rejected
26+
27+
[Unreleased]: https://github.com/Triun/PHP-Longest-Common-Substring/compare/1.0.0...HEAD

CONTRIBUTING.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Contributing
2+
3+
Before you contribute code, please make sure it conforms to the PSR-2 coding standard and that the unit tests still pass. The easiest way to contribute is to work on your own fork.
4+
5+
If you do this, you can run the following commands to check if everything is ready to submit.
6+
7+
## Dependencies
8+
9+
In order to load the dependencies, you should run composer:
10+
11+
```bash
12+
composer install
13+
```
14+
15+
## PSR-2 Specs
16+
17+
This package follows the PSR-2 coding standard.
18+
19+
- [PSR-2: Coding Style Guide]
20+
- [OPNsense PSR-2 Coding Style Guide]
21+
22+
To test if your contribution passes the standard, you can use the command:
23+
24+
```bash
25+
./vendor/bin/phpcs --standard=phpcs.xml
26+
```
27+
28+
Which should give you no output, indicating that there are no coding standard errors.
29+
30+
## Unit testing
31+
32+
You can write your own tests and add them to the `tests` directory.
33+
34+
To run the test command:
35+
36+
```bash
37+
./vendor/bin/phpunit --configuration phpunit.xml --coverage-text
38+
```
39+
40+
Which should give you no failures or errors.
41+
42+
A coverage and logs will be created in the `build` directory.
43+
44+
In order to give support to older versions, you should test it also with the lowest composer packages:
45+
46+
```bash
47+
composer update --prefer-stable --prefer-lowest
48+
```
49+
50+
## Branching and pull requests
51+
52+
As a guideline, please follow this process:
53+
54+
1. [Fork the repository].
55+
2. Create a topic branch for the change:
56+
- New features should branch from **develop**.
57+
- Bug fixes to existing versions should branch from **master**.
58+
- Please ensure the branch is clearly labelled as a feature or fix.
59+
3. Make the relevant changes.
60+
4. [Squash] commits if necessary.
61+
4. Submit a pull request to the **develop** branch.
62+
63+
Please note this is a general guideline only. For more information on the
64+
branching structure please see the [git-flow cheatsheet].
65+
66+
<!-- References -->
67+
68+
[PSR-2: Coding Style Guide]: http://www.php-fig.org/psr/psr-2/
69+
[OPNsense PSR-2 Coding Style Guide]: https://docs.opnsense.org/development/guidelines/psr2.html
70+
[Fork the repository]: https://help.github.com/articles/fork-a-repo
71+
[git-flow cheatsheet]: http://danielkummer.github.com/git-flow-cheatsheet/
72+
[Squash]: http://git-scm.com/book/en/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 Triun
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
PHP - Longest Common Substring
2+
==============================
3+
4+
PHP implementation of an algorithm to solve the `longest common substring` problem.
5+
6+
[![Latest Version on Packagist][ico-version]][link-packagist]
7+
[![Pre Release Version on Packagist][ico-pre-release]][link-packagist]
8+
[![Latest Unstable Version][ico-unstable]][link-packagist]
9+
[![Build Status][ico-travis]][link-travis]
10+
[![Coverage status][ico-codecov]][link-codecov]
11+
[![Total Downloads][ico-downloads]][link-downloads]
12+
[![The most recent stable version is 2.0.0][ico-semver]][link-semver]
13+
[![Software License][ico-license]](LICENSE.md)
14+
15+
# About
16+
17+
*PHP-Longest-Common-Subsequence* is a PHP implementation of an algorithm to solve the 'longest common substring' problem.
18+
19+
From [Wikipedia - Longest common substring problem](https://en.wikipedia.org/wiki/Longest_common_substring_problem):
20+
21+
> In computer science, the longest common substring problem is to find the longest string (or strings) that is a
22+
> substring (or are substrings) of two or more strings.
23+
24+
# Installation
25+
26+
Require [triun/longest-common-substring package](https://packagist.org/packages/triun/longest-common-substring) with [composer](http://getcomposer.org/)
27+
using the following command:
28+
29+
```bash
30+
composer require triun/longest-common-substring
31+
```
32+
33+
# Usage
34+
35+
## Solver
36+
37+
```php
38+
use Triun\LongestCommonSubstring\Solver;
39+
40+
$solver = new Solver();
41+
42+
$stringA = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
43+
$stringB = '56789AB56789ABCDE56789ABCDE56789AB56789A123456789A';
44+
45+
// calculates the LCSubstring to be '123456789A'
46+
$result = $solver->solve($stringA, $stringB);
47+
```
48+
49+
## Matches solver
50+
51+
```php
52+
use Triun\LongestCommonSubstring\Solver;
53+
54+
$solver = new Solver();
55+
56+
$stringA = '0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF';
57+
$stringB = '56789AB56789ABCDE56789ABCDE56789AB56789A123456789A';
58+
59+
$matches = $matchSolver->solve($stringA, $stringB);
60+
61+
// calculates the LCSubstring to be '123456789A'
62+
$result = "$matches";
63+
```
64+
65+
66+
But also can give you the rest of the results which has the same length:
67+
68+
```php
69+
var_dump($matches->values());
70+
```
71+
72+
```
73+
array:12 [
74+
0 => "123456789A"
75+
1 => "56789ABCDE"
76+
2 => "56789ABCDE"
77+
3 => "123456789A"
78+
4 => "56789ABCDE"
79+
5 => "56789ABCDE"
80+
6 => "123456789A"
81+
7 => "56789ABCDE"
82+
8 => "56789ABCDE"
83+
9 => "123456789A"
84+
10 => "56789ABCDE"
85+
11 => "56789ABCDE"
86+
]
87+
```
88+
89+
You can use `unique` to skip duplicated values:
90+
91+
```php
92+
var_dump($matches->unique());
93+
```
94+
95+
```
96+
array:2 [
97+
0 => "123456789A"
98+
1 => "56789ABCDE"
99+
]
100+
```
101+
102+
Or even more information about the matches, like the input strings indexes:
103+
104+
```php
105+
var_dump($matches->values());
106+
```
107+
108+
```
109+
array:12 [
110+
0 => array:3 [
111+
"value" => "123456789A"
112+
"length" => 10
113+
"indexes" => array:2 [
114+
0 => 1
115+
1 => 40
116+
]
117+
]
118+
1 => array:3 [
119+
"value" => "56789ABCDE"
120+
"length" => 10
121+
"indexes" => array:2 [
122+
0 => 5
123+
1 => 7
124+
]
125+
]
126+
2 => array:3 [
127+
"value" => "56789ABCDE"
128+
"length" => 10
129+
"indexes" => array:2 [
130+
0 => 5
131+
1 => 17
132+
]
133+
]
134+
...
135+
]
136+
```
137+
138+
# Issues
139+
140+
Bug reports and feature requests can be submitted on the
141+
[Github Issue Tracker](https://github.com/Triun/PHP-Longest-Common-Substring/issues).
142+
143+
# Contributing
144+
145+
See [CONTRIBUTING.md](CONTRIBUTING.md) for information.
146+
147+
# License
148+
149+
This repository is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
150+
151+
<!-- References -->
152+
153+
[ico-version]: https://img.shields.io/packagist/v/triun/longest-common-substring.svg
154+
[ico-pre-release]: https://img.shields.io/packagist/vpre/triun/longest-common-substring.svg
155+
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
156+
[ico-travis]: https://travis-ci.org/Triun/PHP-Longest-Common-Substring.svg?branch=master
157+
[ico-code-quality]: https://img.shields.io/scrutinizer/g/triun/longest-common-substring.svg?style=flat-square
158+
[ico-downloads]: https://img.shields.io/packagist/dt/triun/longest-common-substring.svg?style=flat-square
159+
[ico-unstable]: https://poser.pugx.org/triun/longest-common-substring/v/unstable
160+
[ico-coveralls]: https://coveralls.io/repos/github/Triun/PHP-Longest-Common-Substring/badge.svg?branch=master "Current test coverage for the develop branch"
161+
[ico-codecov]: https://codecov.io/gh/Triun/PHP-Longest-Common-Substring/branch/master/graph/badge.svg
162+
[ico-semver]: http://img.shields.io/:semver-2.0.0-brightgreen.svg "This project uses semantic versioning"
163+
164+
[link-packagist]: https://packagist.org/packages/triun/longest-common-substring
165+
[link-travis]: https://travis-ci.org/Triun/PHP-Longest-Common-Substring
166+
[link-downloads]: https://packagist.org/packages/triun/longest-common-substring
167+
[link-author]: https://github.com/Triun
168+
[link-coveralls]: https://coveralls.io/github/Triun/PHP-Longest-Common-Substring?branch=master
169+
[link-codecov]: https://codecov.io/gh/Triun/PHP-Longest-Common-Substring
170+
[link-semver]: http://semver.org/

0 commit comments

Comments
 (0)