Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mlantz committed Nov 14, 2024
0 parents commit 6f769a2
Show file tree
Hide file tree
Showing 20 changed files with 643 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
27 changes: 27 additions & 0 deletions .github/workflows/php-package-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: PHP Package Tests

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['8.1']

steps:
- uses: actions/checkout@v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run tests
run: vendor/bin/phpunit
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
composer.phar
composer.lock
.DS_Store
.phpunit.result.cache
1 change: 1 addition & 0 deletions .phpunit.cache/test-results
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"version":1,"defects":{"Tests\\Unit\\CacheTest::testCacheProvider":8},"times":{"Tests\\Unit\\CacheTest::testCacheProvider":0.036,"Tests\\Unit\\CacheTest::testCacheKeyMaker":0.001}}
9 changes: 9 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
preset: recommended

risky: false

linting: true

finder:
exclude:
- "tests"
56 changes: 56 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Contributions are always welcome

## Quick guide

* Fork the repo.
* Checkout the branch you want to make changes on:
* Develop branch in 95% of the cases.
* Install the dependencies: `composer install`.
* Create branch such as: `feature-foo` or `fix-bar`.
* Write some awesome code!
* Add some tests, and ensure your code is PSR-2 compliant.
* Submit your Pull Request

## When opening a pull request
You can do some things to increase the chance that your pull request is accepted the first time:

* Submit one pull request per fix or feature.
* If your changes are not up to date - rebase your branch on the parent branch.
* Follow the conventions used in the project.
* Remember about tests and documentation.

## Naming Conventions

* Use camelCase, not underscores, for variable, function and method names, arguments.
* Use namespaces for all classes.
* Prefix abstract classes with Abstract.
* Suffix interfaces with Interface.
* Suffix traits with Trait.
* Suffix exceptions with Exception.
* Suffix services with Service.
* Use alphanumeric characters and underscores for file names.

## PHPDoc

We generally follow the doc standards of Laravel.

```
/**
* Register a binding with the container.
*
* @param string|array $abstract
* @param \Closure|string|null $concrete
* @param bool $shared
* @return void
*/
public function bind($abstract, $concrete = null, $shared = false)
{
//
}
```

## Other general standards we follow
* [PSR-1: Basic Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md)
* [PSR-2: Coding Style Guide](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)
* [PSR-4: Autoloading Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md)
* [Symfony Coding Standards](http://symfony.com/doc/current/contributing/code/standards.html)
Binary file added GrafiteSupport-banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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) 2024 Matt Lantz

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.
10 changes: 10 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Grafite Support License

The MIT License (MIT)
Copyright (c) Grafite Inc.

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.
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
![Grafite Cache](GrafiteCache-banner.png)

**Cache** - SQLite based cache driver with some fancy extras like tagging and encryption etc.

[![Build Status](https://github.com/GrafiteInc/Cache/workflows/PHP%20Package%20Tests/badge.svg?branch=main)](https://github.com/GrafiteInc/Cache/actions?query=workflow%3A%22PHP+Package+Tests%22)
[![Maintainability](https://api.codeclimate.com/v1/badges/a90e41bd64d41508ef0e/maintainability)](https://codeclimate.com/github/GrafiteInc/Cache/maintainability)
[![Packagist](https://img.shields.io/packagist/dt/grafite/cache.svg)](https://packagist.org/packages/grafite/cache)
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://packagist.org/packages/grafite/cache)

The Cache package an SQLite based cache driver with some fancy extras like tagging and encryption.

##### Author(s):
* [Matt Lantz](https://github.com/mlantz) ([@mattylantz](http://twitter.com/mattylantz), mattlantz at gmail dot com)

## Requirements

1. PHP 8.2+

## Compatibility and Support

| Laravel Version | Package Tag | Supported |
|-----------------|-------------|-----------|
| ^11.x | 1.x | yes |

### Installation

Start a new Laravel project:
```php
composer create-project laravel/laravel your-project-name
```

Then run the following to add Support
```php
composer require "grafite/cache"
```

Append to the `cache.php` config file in the stores array:
```php
'sqlite' => [
'driver' => 'sqlite',
'table' => 'cache',
'database' => env('CACHE_DATABASE', database_path('cache.sqlite')),
'prefix' => '',
],
```

## Documentation

[https://docs.grafite.ca/utilities/cache](https://docs.grafite.ca/utilities/cache)

## License
Support is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

### Bug Reporting and Feature Requests
Please add as many details as possible regarding submission of issues and feature requests

### Disclaimer
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.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log - Grafite Cache
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).
----
55 changes: 55 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "grafite/cache",
"description": "An SQLite based cache with some extra features.",
"license": "MIT",
"keywords": [
"Laravel"
],
"authors": [
{
"name": "Matt Lantz",
"email": "[email protected]"
}
],
"require": {
"php": "^8.2",
"illuminate/support": "^11.0",
"illuminate/collections": "^11.0"
},
"require-dev": {
"phpunit/phpunit": "^10.0",
"mockery/mockery": "^1.0",
"laravel/pint": "^1.10",
"orchestra/testbench": "^8.0|^9.0"
},
"autoload": {
"psr-4": {
"Grafite\\Cache\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Grafite\\Cache\\CacheProvider"
]
}
},
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"check-style": "vendor/bin/pint --test",
"fix-style": "vendor/bin/pint",
"insights": "vendor/bin/phpinsights",
"test": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover clover.xml && php coverage-checker.php clover.xml 50"
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
33 changes: 33 additions & 0 deletions coverage-checker.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

// coverage-checker.php
$inputFile = $argv[1];
$percentage = min(100, max(0, (int) $argv[2]));

if (! file_exists($inputFile)) {
throw new InvalidArgumentException('Invalid input file provided');
}

if (! $percentage) {
throw new InvalidArgumentException('An integer checked percentage must be given as second parameter');
}

$xml = new SimpleXMLElement(file_get_contents($inputFile));
$metrics = $xml->xpath('//metrics');
$totalElements = 0;
$checkedElements = 0;

foreach ($metrics as $metric) {
$totalElements += (int) $metric['elements'];
$checkedElements += (int) $metric['coveredelements'];
}

$coverage = ($checkedElements / $totalElements) * 100;

if ($coverage < $percentage) {
echo 'Code coverage is '.$coverage.'%, which is below the accepted '.$percentage.'%'.PHP_EOL;

exit(1);
}

echo 'Code coverage is '.$coverage.'% - OK!'.PHP_EOL;
19 changes: 19 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit/</directory>
</testsuite>
</testsuites>
<coverage/>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
<php>
<server name="APP_ENV" value="testing"/>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<server name="CACHE_DRIVER" value="sqlite"/>
</php>
</phpunit>
Loading

0 comments on commit 6f769a2

Please sign in to comment.