Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modernize #13

Merged
merged 20 commits into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Test
on: [pull_request]

jobs:
psalm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Psalm
uses: docker://vimeo/psalm-github-actions
with:
security_analysis: true
report_file: results.sarif

- name: Upload Security Analysis results to GitHub
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: results.sarif

# codecov:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0

# - name: Cache Composer dependencies
# uses: actions/cache@v2
# with:
# path: /tmp/composer-cache
# key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

# - uses: php-actions/composer@v5

# - uses: php-actions/phpunit@v2
# env:
# XDEBUG_MODE: coverage
# with:
# php_extensions: xdebug
# args: --coverage-clover coverage.xml

# - uses: codecov/codecov-action@v1
# with:
# file: ./coverage.xml
# fail_ci_if_error: true
# verbose: true

test:
runs-on: ubuntu-latest
strategy:
matrix:
php:
- 7.1
- 7.2
- 7.3
- 7.4
- 8.0
include:
- php: 7.1
phpunit: 7.5.20
- php: 7.2
phpunit: 8.5.13
- php: 7.3
phpunit: 9.5.0
- php: 7.4
phpunit: 9.5.0
- php: 8.0
phpunit: 9.5.0

steps:
- uses: actions/checkout@v2

- name: Cache Composer dependencies
uses: actions/cache@v2
with:
path: /tmp/composer-cache
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}

- uses: php-actions/composer@v5
with:
php_version: ${{ matrix.php }}

- uses: php-actions/phpunit@v2
with:
php_version: ${{ matrix.php }}
version: ${{ matrix.phpunit }}
21 changes: 21 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Release
on: [workflow_dispatch]
jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:

- name: Setup Node.js for use with actions
uses: actions/[email protected]

- name: Checkout
uses: actions/checkout@v2

- name: Unshallow
run: git fetch --prune --unshallow

- name: Run semantic-release
run: npx -p @semantic-release/changelog -p [email protected] -p @semantic-release/git semantic-release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
15 changes: 15 additions & 0 deletions .releaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/changelog"
- "@semantic-release/github"
- "@semantic-release/git"
branch: master
branches:
- '+([0-9])?(.{+([0-9]),x}).x'
- 'main'
- 'next'
- 'next-major'
- {name: 'beta', prerelease: true}
- {name: 'alpha', prerelease: true}
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Enrico Stahn

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.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ json-query-wrapper is a wrapper for the popular command-line JSON processor "[jq
## Installation

```bash
$ composer require estahn/json-query-wrapper
$ composer require invoicesharing/json-query-wrapper
```

## Usage
Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "library",
"description": "Wrapper for jq, a lightweight and flexible command-line JSON processor",
"keywords": ["jq", "json", "query"],
"homepage": "https://github.com/estahn/jq-wrapper",
"homepage": "https://github.com/estahn/json-query-wrapper",
"license": "MIT",
"authors": [
{
Expand All @@ -13,12 +13,12 @@
],
"minimum-stability": "dev",
"require": {
"php": ">=5.3.0",
"symfony/process": "~2.8|~3.0"
"php": "^7.1|^8",
"symfony/process": "^4|^5"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0",
"codacy/coverage": "dev-master"
"phpunit/phpunit": "^7|^8|^9",
"vimeo/psalm": "4.x-dev"
},
"autoload": {
"psr-4": {
Expand Down
38 changes: 11 additions & 27 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- http://phpunit.de/manual/4.1/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/4.1/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="JSON Query Wrapper Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src/JsonQueryWrapper/</directory>
</whitelist>
</filter>

<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-html" target="build/logs/report" charset="UTF-8"
yui="true" highlight="true"
lowUpperBound="50" highLowerBound="80"/>
<log type="testdox-html" target="build/logs/testdox.html" />
</logging>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" colors="true" bootstrap="vendor/autoload.php">
<coverage>
<include>
<directory suffix=".php">src/JsonQueryWrapper/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="JSON Query Wrapper Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
15 changes: 13 additions & 2 deletions src/JsonQueryWrapper/DataProvider/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ class Text implements DataProviderInterface
*/
protected $path;

/**
* Pointer to the file required
* When the php process finish deletes the temp file, with this attribute pointing to the temp file php waits to remove
* the file until is not is finished
*
* @var resource
*/
protected $file;

/**
* Text constructor.
*
Expand All @@ -48,8 +57,10 @@ public function __construct($data)
public function getPath()
{
if (empty($this->path)) {
$this->path = tempnam(sys_get_temp_dir(), 'jq');
file_put_contents($this->path, $this->data);
$this->file = tmpfile();
fwrite($this->file, $this->data);
$metadata = stream_get_meta_data($this->file);
$this->path = $metadata['uri'];
}

return $this->path;
Expand Down
34 changes: 11 additions & 23 deletions src/JsonQueryWrapper/JsonQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@

use JsonQueryWrapper\DataProvider\DataProviderInterface;
use JsonQueryWrapper\Exception\DataProviderMissingException;
use Symfony\Component\Process\ProcessBuilder;
use JsonQueryWrapper\Process\ProcessFactoryInterface;

/**
* Class JsonQuery.
*/
class JsonQuery
{
/**
* @var ProcessBuilder
* @var ProcessFactoryInterface
*/
protected $builder;
protected $processFactory;

/**
* @var DataTypeMapper
Expand All @@ -45,46 +45,34 @@ class JsonQuery
/**
* JsonQuery constructor.
*
* @param ProcessBuilder $builder
* @param ProcessFactoryInterface $processFactory
* @param DataTypeMapper $dataTypeMapper
*/
public function __construct(ProcessBuilder $builder, DataTypeMapper $dataTypeMapper)
public function __construct(ProcessFactoryInterface $processFactory, DataTypeMapper $dataTypeMapper)
{
$this->builder = $builder;
$this->processFactory = $processFactory;
$this->mapper = $dataTypeMapper;
}

/**
* Set the path to the jq command.
*
* @param string $cmd
*/
public function setCmd($cmd)
{
$this->cmd = $cmd;
}

/**
* Runs the command-line and returns.
*
* @param string $filter
*
* @throws DataProviderMissingException
*
* @return mixed
* @throws DataProviderMissingException
* @throws Exception\DataTypeMapperException
*/
public function run($filter)
{
if (!$this->dataProvider instanceof DataProviderInterface) {
throw new DataProviderMissingException('A data provider such as file or text is missing.');
}

$builder = $this->builder;
$builder
->setPrefix($this->cmd)
->setArguments(['-M', $filter, $this->dataProvider->getPath()]);
$command = [$this->cmd, '-M', $filter, $this->dataProvider->getPath()];

$process = $this->processFactory->build($command);

$process = $builder->getProcess();
$process->run();

$result = trim($process->getOutput());
Expand Down
Loading