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

Clean class and function files as per PSR-4 #98

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
vendor/
/vendor/
/composer.lock
composer.phar
.DS_Store

Expand Down
1 change: 1 addition & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ checks:
filter:
excluded_paths:
- "tests/"
- "patchwork-composer/"
- "vendor/"
coding_style:
php:
Expand Down
90 changes: 6 additions & 84 deletions Patchwork.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,93 +7,17 @@
*/
namespace Patchwork;

if (function_exists('Patchwork\replace')) {
if (defined('Patchwork\PATCHWORK_ALREADY_RAN')) {
return;
}

require_once __DIR__ . '/src/Exceptions.php';
require_once __DIR__ . '/src/CallRerouting.php';
require_once __DIR__ . '/src/CodeManipulation.php';
require_once __DIR__ . '/src/Utils.php';
require_once __DIR__ . '/src/Stack.php';
require_once __DIR__ . '/src/Config.php';

function redefine($subject, callable $content)
{
$handle = null;
foreach (array_slice(func_get_args(), 1) as $content) {
$handle = CallRerouting\connect($subject, $content, $handle);
}
$handle->silence();
return $handle;
}

function relay(array $args = null)
{
return CallRerouting\relay($args);
}
const PATCHWORK_ALREADY_RAN = true;

function fallBack()
{
throw new Exceptions\NoResult;
// Load all class and function files if Composer is not running.
if (! function_exists('Patchwork\replace')) {
require_once __DIR__ . '/patchwork-composer/autoload.php';
}

function restore(CallRerouting\Handle $handle)
{
$handle->expire();
}

function restoreAll()
{
CallRerouting\disconnectAll();
}

function silence(CallRerouting\Handle $handle)
{
$handle->silence();
}

function assertEventuallyDefined(CallRerouting\Handle $handle)
{
$handle->unsilence();
}

function getClass()
{
return Stack\top('class');
}

function getCalledClass()
{
return Stack\topCalledClass();
}

function getFunction()
{
return Stack\top('function');
}

function getMethod()
{
return getClass() . '::' . getFunction();
}

function configure()
{
Config\locate();
}

function hasMissed($callable)
{
return Utils\callableWasMissed($callable);
}

function always($value)
{
return function() use ($value) {
return $value;
};
}

Utils\alias('Patchwork', [
'redefine' => ['replace', 'replaceLater'],
Expand Down Expand Up @@ -137,13 +61,11 @@ function always($value)
CallRerouting\createStubsForInternals();
CallRerouting\connectDefaultInternals();

require __DIR__ . '/src/Redefinitions/LanguageConstructs.php';

CodeManipulation\register([
CodeManipulation\Actions\RedefinitionOfLanguageConstructs\spliceAllConfiguredLanguageConstructs(),
CodeManipulation\Actions\CallRerouting\injectQueueDeploymentCode(),
]);

if (Utils\wasRunAsConsoleApp()) {
require __DIR__ . '/src/Console.php';
require __DIR__ . '/src/Console/console.php';
}
22 changes: 22 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,27 @@
},
"require-dev": {
"phpunit/phpunit": ">=4"
},
"autoload": {
"files": [
"src/functions.php",
"src/CallRerouting/functions.php",
"src/CodeManipulation/Actions/CallRerouting/functions.php",
"src/CodeManipulation/Actions/CodeManipulation/functions.php",
"src/CodeManipulation/Actions/ConflictPrevention/functions.php",
"src/CodeManipulation/Actions/Generic/functions.php",
"src/CodeManipulation/Actions/Namespaces/functions.php",
"src/CodeManipulation/Actions/RedefinitionOfInternals/functions.php",
"src/CodeManipulation/Actions/RedefinitionOfLanguageConstructs/functions.php",
"src/CodeManipulation/Actions/RedefinitionOfNew/functions.php",
"src/CodeManipulation/functions.php",
"src/Config/functions.php",
"src/Redefinitions/LanguageConstructs/functions.php",
"src/Stack/functions.php",
"src/Utils/functions.php"
],
"psr-4": {
"Patchwork\\": "src/"
}
}
}
43 changes: 43 additions & 0 deletions patchwork-composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"name": "antecedent/patchwork",
"homepage": "http://patchwork2.org/",
"description": "Method redefinition (monkey-patching) functionality for PHP.",
"keywords": ["testing", "redefinition", "runkit", "monkeypatching", "interception", "aop", "aspect"],
"license": "MIT",
"authors": [
{
"name": "Ignas Rudaitis",
"email": "ignas.rudaitis@gmail.com"
}
],
"minimum-stability": "stable",
"require": {
"php": ">=5.4.0"
},
"autoload": {
"files": [
"src/functions.php",
"src/CallRerouting/functions.php",
"src/CodeManipulation/Actions/CallRerouting/functions.php",
"src/CodeManipulation/Actions/CodeManipulation/functions.php",
"src/CodeManipulation/Actions/ConflictPrevention/functions.php",
"src/CodeManipulation/Actions/Generic/functions.php",
"src/CodeManipulation/Actions/Namespaces/functions.php",
"src/CodeManipulation/Actions/RedefinitionOfInternals/functions.php",
"src/CodeManipulation/Actions/RedefinitionOfLanguageConstructs/functions.php",
"src/CodeManipulation/Actions/RedefinitionOfNew/functions.php",
"src/CodeManipulation/functions.php",
"src/Config/functions.php",
"src/Redefinitions/LanguageConstructs/functions.php",
"src/Stack/functions.php",
"src/Utils/functions.php"
],
"psr-4": {
"Patchwork\\": "src/"
}
},
"config": {
"vendor-dir": "patchwork-composer",
"optimize-autoloader": true
}
}
7 changes: 7 additions & 0 deletions patchwork-composer/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

// autoload.php @generated by Composer

require_once __DIR__ . '/composer/autoload_real.php';

return ComposerAutoloaderInitb7de713a68964186ce39fad9ae1c996a::getLoader();
Loading