Skip to content

Commit

Permalink
Initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
brendankay committed Mar 14, 2018
0 parents commit 28314fd
Show file tree
Hide file tree
Showing 32 changed files with 2,911 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor/
31 changes: 31 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: php

dist: trusty

cache:
directories:
- $HOME/.composer/cache/files

php:
- 5.6
- 7.0
- 7.1
- hhvm
- nightly

env:
- PREFER_LOWEST=--prefer-lowest
- PREFER_LOWEST=

matrix:
allow_failures:
- php: nightly

before_script:
- travis_retry composer update --no-interaction --prefer-dist $PREFER_LOWEST

script:
- make lint test-coverage-clover

after_script:
- test -f ./tests/report/coverage.clover && (wget https://scrutinizer-ci.com/ocular.phar; php ocular.phar code-coverage:upload --format=php-clover ./tests/report/coverage.clover)
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Change Log

All Notable changes to `graze/wipotec-checkweigher-client` will be documented in this file

## v1.0.0 - 2018-03-07

- Initial release
34 changes: 34 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Contributing

Contributions are **welcome**!

We accept contributions via Pull Requests on [Github](https://github.com/graze/wipotec-checkweigher-client). We also recommend reading [How to write the perfect Pull Request](https://github.com/blog/1943-how-to-write-the-perfect-pull-request) which has some great tips and advice.

## Reporting an Issue

Please report issues via the issue tracker on GitHub. For security-related issues, please email the maintainer directly.

## Pull Requests

Contributions are accepted via Pull Requests. In order for your Pull Request to be merged, please ensure it meets
the following criteria:

- **PSR-2 & PSR-4 Coding Standards**.
- **Tests** - your contribution will not be merged unless it has tests covering the changes.
- **Documentation** - please ensure that README.md and any other documentation relevant to your change is up-to-date.
- **Description** - please provide a description of your pull request that details the changes you've made, why you've
made them including any relevant information or justifications that will aid the person reviewing you changes.

```shell
$ make build
```

A complete list of commands can be found by running: `$ make help`

## Running Tests

You can run all of the test suites in the project using:

```shell
$ make test
```
21 changes: 21 additions & 0 deletions LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 Nature Delivered Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
43 changes: 43 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
SHELL = /bin/sh

.PHONY: build build-update clean help test lint lint-fix test-unit test-coverage

.SILENT: help

build: ## Download the dependencies then build the image :rocket:.
composer install

build-update: ## Update all dependencies
composer update

# Testing

test: ## Run the unit and integration testsuites.
test: lint test-unit

lint: ## Run phpcs against the code.
vendor/bin/phpcs -p --warning-severity=0 src/ tests/

lint-fix: ## Run phpcsf and fix possible lint errors.
vendor/bin/phpcbf -p src/ tests/

test-unit: ## Run the unit testsuite.
vendor/bin/phpunit --testsuite unit

test-coverage: ## Run all tests and output coverage to the console.
vendor/bin/phpunit --coverage-text

test-coverage-html: ## Run all tests and output coverage to html.
vendor/bin/phpunit --coverage-html=./tests/report/html

test-coverage-clover: ## Run all tests and output clover coverage to file.
vendor/bin/phpunit --coverage-clover=./tests/report/coverage.clover

clean: ## Stop running containers and clean up an images.
rm -rf vendor/

help: ## Show this help message.
echo "usage: make [target] ..."
echo ""
echo "targets:"
fgrep --no-filename "##" $(MAKEFILE_LIST) | fgrep --invert-match $$'\t' | sed -e 's/## / /'
107 changes: 107 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# wipotec-checkweigher-client

[![Latest Version on Packagist](https://img.shields.io/packagist/v/graze/wipotec-checkweigher-client.svg?style=flat-square)](https://packagist.org/packages/graze/wipotec-checkweigher-client)
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
[![Build Status](https://img.shields.io/travis/graze/wipotec-checkweigher-client/master.svg?style=flat-square)](https://travis-ci.org/graze/wipotec-checkweigher-client)
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/graze/wipotec-checkweigher-client.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/wipotec-checkweigher-client/code-structure)
[![Quality Score](https://img.shields.io/scrutinizer/g/graze/wipotec-checkweigher-client.svg?style=flat-square)](https://scrutinizer-ci.com/g/graze/wipotec-checkweigher-client)
[![Total Downloads](https://img.shields.io/packagist/dt/graze/wipotec-checkweigher-client.svg?style=flat-square)](https://packagist.org/packages/graze/wipotec-checkweigher-client)

Wipotec checkweigher client written in PHP.

## Install

Via Composer

``` bash
$ composer require graze/wipotec-checkweigher-client
```

## Usage

### Instantiating a client

Use the `factory` method to return a `Client` instance:

```php
$client = \Graze\WipotecCheckweigherClient\Client::factory();
...
```

### Sending requests

Connect to the remote checkweigher using the `connect` method:

```php
...
$dsn = '127.0.0.1:55001';
$client->connect($dsn);
...
```

Once connected, the `sendRequest` method can be used to send requests to the checkweigher:

```php
...
$request = new \Graze\WipotecCheckweigherClient\Request\RequestSetArticle();
$request->setArticleParam(Parameter::NAME, $articleName);
$request->setArticleParam(Parameter::NUMBER, $articleNumber);
$response = $client->sendRequest($request);
...
```

### Responses

If a corresponding response class exists (in `\Graze\Wipotec\Response\`) for a request then it will be used, otherwise the `ResponseGeneric` will be returned.

All responses have the following methods:

```php
/**
* Whether an error was returned.
*
* @return bool
*/
public function hasError();

/**
* Get the error message.
*
* @return string
*/
public function getError();

/**
* Get the raw response as an array.
*
* @return mixed[]
*/
public function getContents();
```

## Change log

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

## Testing

```shell
make build test
```

## Contributing

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

## Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

## Credits

- [Brendan Kay](https://github.com/brendankay)
- [All Contributors](../../contributors)

## License

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "graze/wipotec-checkweigher-client",
"description": "Wipotec checkweigher client written in PHP",
"keywords": [
"graze",
"wipotec",
"checkweigher"
],
"homepage": "https://github.com/graze/wipotec-checkweigher-client",
"license": "MIT",
"authors": [
{
"name": "Brendan Kay",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "Graze Developers",
"email": "[email protected]",
"homepage": "http://www.graze.com",
"role": "Development Team"
}
],
"require": {
"php": ">=5.6",
"graze/telnet-client": "^2.0.2",
"graze/xml-utils": "^1.0.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7.21",
"squizlabs/php_codesniffer": "^3.0",
"graze/standards": "^2.0",
"mockery/mockery": "^1.0"
},
"autoload": {
"psr-4": {
"Graze\\WipotecCheckweigherClient\\": "src"
}
},
"autoload-dev": {
"psr-4": {
"Graze\\WipotecCheckweigherClient\\Test\\Unit\\": "tests/unit"
}
}
}
Loading

0 comments on commit 28314fd

Please sign in to comment.