Skip to content

Commit

Permalink
Merge branch 'release/1.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
BracketSpaceWorker committed Nov 28, 2022
2 parents 0e5d10d + 17efad9 commit fbe11c5
Show file tree
Hide file tree
Showing 10 changed files with 571 additions and 1 deletion.
52 changes: 52 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Release

on:
workflow_dispatch:
inputs:
new_version:
description: 'New version'
required: true

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout master
uses: actions/checkout@v1
with:
ref: 'master'
- name: Checkout develop
uses: actions/checkout@v1
with:
ref: 'develop'
clean: false
- name: Install git-flow
run: sudo apt-get install git-flow -y
- name: Configure commiter
run: |
git config --local user.email "${{ secrets.WORKER_EMAIL }}"
git config --local user.name "${{ secrets.WORKER_NAME }}"
- name: Init git-flow
run: git flow init -d
- name: Start release
run: git flow release start ${{ github.event.inputs.new_version }}
- name: Replace 1.0.0 tags with new version number
uses: jacobtomlinson/gha-find-replace@master
with:
find: "(?i)\\[Next\\]"
replace: "${{ github.event.inputs.new_version }}"
- name: Commit version bump
run: git commit -am "Version bump"
- name: Finish release
run: git flow release finish ${{ github.event.inputs.new_version }} -m "v${{ github.event.inputs.new_version }}"
- name: Push develop and tags
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.WORKER_TOKEN }}
branch: 'develop'
- name: Push master
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.WORKER_TOKEN }}
branch: 'master'
29 changes: 29 additions & 0 deletions .github/workflows/stable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Stable

on:
push:
tags:
- '*'

jobs:

# Release on GitHub
github-release:
name: Release on GitHub
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Parse changelog
run: |
START="## ${{ steps.vars.outputs.version }}"
END="## [0-9]+.[0-9]+.[0-9]+|\$"
grep -oPz "(?s)${START}.*?\n\K.*?(?=${END})" CHANGELOG.md > changelog.txt
truncate -s-3 changelog.txt
sed -i '1d' changelog.txt
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: changelog.txt
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog
All notable changes to this project will be documented in this file.

## 1.0.0

Initial release
74 changes: 74 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Casegnostic

[![BracketSpace Micropackage](https://img.shields.io/badge/BracketSpace-Micropackage-brightgreen)](https://bracketspace.com)
[![Latest Stable Version](https://poser.pugx.org/micropackage/dochooks/v/stable)](https://packagist.org/packages/micropackage/dochooks)
[![PHP from Packagist](https://img.shields.io/packagist/php-v/micropackage/dochooks.svg)](https://packagist.org/packages/micropackage/dochooks)
[![Total Downloads](https://poser.pugx.org/micropackage/dochooks/downloads)](https://packagist.org/packages/micropackage/dochooks)
[![License](https://poser.pugx.org/micropackage/dochooks/license)](https://packagist.org/packages/micropackage/dochooks)

<p align="center">
<img src="https://bracketspace.com/extras/micropackage/micropackage-small.png" alt="Micropackage logo"/>
</p>

## 🧬 About Casegnostic

Package that simplifies transition from one coding standard to other, namely from snake_case to camelCase or vice-versa.

When you're about to break compatibility by changing method name from something_important() to somethingImportant() you can simply attach the trait.

```php
use Micropackage\Casegnostic\Casegnostic;

class Example
{
use Casegnostic;

public function somethingImportant()
{
return true;
}
}

$x = new Example();

// That works as expected:
$x->somethingImportant();

// But that works too! 🤯
$x->something_important();
```

## 💾 Installation

``` bash
composer require micropackage/casegnostic
```

## 🕹 Usage

Simply attach the trait to your class.

```php
use Micropackage\Casegnostic\Casegnostic;

class Example
{
use Casegnostic;
}
```

## 📦 About the Micropackage project

Micropackages - as the name suggests - are micro packages with a tiny bit of reusable code, helpful particularly in WordPress development.

The aim is to have multiple packages which can be put together to create something bigger by defining only the structure.

Micropackages are maintained by [BracketSpace](https://bracketspace.com).

## 📖 Changelog

[See the changelog file](./CHANGELOG.md).

## 📃 License

GNU General Public License (GPL) v3.0. See the [LICENSE](./LICENSE) file for more information.
12 changes: 11 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@
<exclude name="WordPress.NamingConventions.ValidHookName.UseUnderscores"/>

<exclude name="NeutronStandard.Functions.LongFunction.LongFunction"/>

<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterOpen"/>
<exclude name="NeutronStandard.MagicMethods.DisallowMagicGet.MagicGet"/>

<exclude name="NeutronStandard.MagicMethods.RiskyMagicMethod.RiskyMagicMethod"/>
<exclude name="NeutronStandard.MagicMethods.DisallowMagicSet.MagicSet"/>
</rule>

<rule ref="PSR12">
<exclude name="PSR12.Files.FileHeader" />
<exclude name="PSR12.Files.OpenTag" />
<exclude name="Generic.WhiteSpace.DisallowTabIndent" />
</rule>

<!-- Use tabs instead of spaces for indentation -->
<rule ref="Generic.WhiteSpace.DisallowSpaceIndent" />
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="tabIndent" value="true" />
</properties>
</rule>

<rule ref="Squiz.PHP.DiscouragedFunctions">
Expand Down
152 changes: 152 additions & 0 deletions src/Casegnostic.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
<?php

declare(strict_types=1);

/**
* Casegnostic
*
* @package micropackage/casegnostic
*/

namespace Micropackage\Casegnostic;

use Micropackage\Casegnostic\Helpers\CaseHelper;

/**
* Casegnostic trait
*/
trait Casegnostic
{
/**
* @param string $name
* @return mixed|void
* @throws \Exception
*/
public function __get(string $name)
{
if (CaseHelper::isSnake($name)) {
if (property_exists($this, CaseHelper::toCamel($name))) {
return $this->{CaseHelper::toCamel($name)};
}
}

if (!CaseHelper::isCamel($name)) {
return;
}

if (property_exists($this, CaseHelper::toSnake($name))) {
return $this->{CaseHelper::toSnake($name)};
}
}

/**
* @param string $name
* @param mixed $value
* @return void
* @throws \Exception
*/
public function __set(string $name, $value)
{
if (CaseHelper::isSnake($name)) {
if (property_exists($this, CaseHelper::toCamel($name))) {
$this->{CaseHelper::toCamel($name)} = $value;
}
}

if (!CaseHelper::isCamel($name)) {
return;
}

if (!property_exists($this, CaseHelper::toSnake($name))) {
return;
}

$this->{CaseHelper::toSnake($name)} = $value;
}

/**
* @param string $name
* @param array<mixed> $arguments
* @return mixed
* @throws \Exception
*/
public function __call(string $name, array $arguments)
{
if (CaseHelper::isSnake($name)) {
if (method_exists($this, CaseHelper::toCamel($name))) {
return $this->{CaseHelper::toCamel($name)}(...$arguments);
}
}

if (CaseHelper::isCamel($name)) {
if (method_exists($this, CaseHelper::toSnake($name))) {
return $this->{CaseHelper::toSnake($name)}(...$arguments);
}
}

throw new \BadMethodCallException("Method \"{$name}\" does not exist.");
}

/**
* @param string $name
* @param array<mixed> $arguments
* @return mixed
* @throws \Exception
*/
public static function __callStatic(string $name, array $arguments)
{
if (CaseHelper::isSnake($name)) {
if (method_exists(self::class, CaseHelper::toCamel($name))) {
return static::{CaseHelper::toCamel($name)}(...$arguments);
}
}

if (CaseHelper::isCamel($name)) {
if (method_exists(self::class, CaseHelper::toSnake($name))) {
return static::{CaseHelper::toSnake($name)}(...$arguments);
}
}

throw new \BadMethodCallException("Static method \"{$name}\" does not exist.");
}

/**
* @param string $name
* @return bool
* @throws \Exception
*/
public function __isset(string $name)
{
if (CaseHelper::isSnake($name)) {
return isset($this->{CaseHelper::toCamel($name)});
}

if (CaseHelper::isCamel($name)) {
return isset($this->{CaseHelper::toSnake($name)});
}

return false;
}

/**
* @param string $name
* @return void
* @throws \Exception
*/
public function __unset(string $name)
{
if (CaseHelper::isSnake($name)) {
if (isset($this->{CaseHelper::toCamel($name)})) {
unset($this->{CaseHelper::toCamel($name)});
}
}

if (CaseHelper::isCamel($name)) {
if (isset($this->{CaseHelper::toSnake($name)})) {
unset($this->{CaseHelper::toSnake($name)});
}
}

throw new \InvalidArgumentException("Can't find value \"{$name}\" to unset.");
}
}
Loading

0 comments on commit fbe11c5

Please sign in to comment.