pax_global_header00006660000000000000000000000064126575503720014526gustar00rootroot0000000000000052 comment=c36f5e7cfce482fde5bf8d10d41a53591e0198fe code-unit-reverse-lookup-1.0.0/000077500000000000000000000000001265755037200163735ustar00rootroot00000000000000code-unit-reverse-lookup-1.0.0/.gitignore000066400000000000000000000001451265755037200203630ustar00rootroot00000000000000.idea composer.lock composer.phar vendor/ cache.properties build/LICENSE build/README.md build/*.tgz code-unit-reverse-lookup-1.0.0/.php_cs000066400000000000000000000036211265755037200176520ustar00rootroot00000000000000files() ->in('src') ->in('tests') ->name('*.php'); return Symfony\CS\Config\Config::create() ->level(\Symfony\CS\FixerInterface::NONE_LEVEL) ->fixers( array( 'align_double_arrow', 'align_equals', 'braces', 'concat_with_spaces', 'duplicate_semicolon', 'elseif', 'empty_return', 'encoding', 'eof_ending', 'extra_empty_lines', 'function_call_space', 'function_declaration', 'indentation', 'join_function', 'line_after_namespace', 'linefeed', 'list_commas', 'lowercase_constants', 'lowercase_keywords', 'method_argument_space', 'multiple_use', 'namespace_no_leading_whitespace', 'no_blank_lines_after_class_opening', 'no_empty_lines_after_phpdocs', 'parenthesis', 'php_closing_tag', 'phpdoc_indent', 'phpdoc_no_access', 'phpdoc_no_empty_return', 'phpdoc_no_package', 'phpdoc_params', 'phpdoc_scalar', 'phpdoc_separation', 'phpdoc_to_comment', 'phpdoc_trim', 'phpdoc_types', 'phpdoc_var_without_name', 'remove_lines_between_uses', 'return', 'self_accessor', 'short_array_syntax', 'short_tag', 'single_line_after_imports', 'single_quote', 'spaces_before_semicolon', 'spaces_cast', 'ternary_spaces', 'trailing_spaces', 'trim_array_spaces', 'unused_use', 'visibility', 'whitespacy_lines' ) ) ->finder($finder); code-unit-reverse-lookup-1.0.0/.travis.yml000066400000000000000000000003231265755037200205020ustar00rootroot00000000000000language: php php: - 5.6 - 7.0 sudo: false before_script: - composer self-update - composer install --no-interaction --prefer-source --dev script: ./vendor/bin/phpunit notifications: email: false code-unit-reverse-lookup-1.0.0/ChangeLog.md000066400000000000000000000003511265755037200205430ustar00rootroot00000000000000# Change Log All notable changes to `sebastianbergmann/code-unit-reverse-lookup` are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles. ## 1.0.0 - 2016-02-13 ### Added * Initial release code-unit-reverse-lookup-1.0.0/LICENSE000066400000000000000000000030221265755037200173750ustar00rootroot00000000000000code-unit-reverse-lookup Copyright (c) 2016, Sebastian Bergmann . All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of Sebastian Bergmann nor the names of his contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. code-unit-reverse-lookup-1.0.0/README.md000066400000000000000000000007671265755037200176640ustar00rootroot00000000000000# code-unit-reverse-lookup Looks up which function or method a line of code belongs to. ## Installation To add this component as a local, per-project dependency to your project, simply add a dependency on `sebastian/code-unit-reverse-lookup` to your project's `composer.json` file. Here is a minimal example of a `composer.json` file that just defines a dependency on version 1.0 of this component: { "require": { "sebastian/code-unit-reverse-lookup": "~1.0" } } code-unit-reverse-lookup-1.0.0/build.xml000066400000000000000000000017001265755037200202120ustar00rootroot00000000000000 code-unit-reverse-lookup-1.0.0/composer.json000066400000000000000000000012211265755037200211110ustar00rootroot00000000000000{ "name": "sebastian/code-unit-reverse-lookup", "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", "license": "BSD-3-Clause", "authors": [ { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" } ], "require": { "php": ">=5.6" }, "require-dev": { "phpunit/phpunit": "~5" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } } } code-unit-reverse-lookup-1.0.0/phpunit.xml000066400000000000000000000014161265755037200206060ustar00rootroot00000000000000 tests src code-unit-reverse-lookup-1.0.0/src/000077500000000000000000000000001265755037200171625ustar00rootroot00000000000000code-unit-reverse-lookup-1.0.0/src/Wizard.php000066400000000000000000000055451265755037200211440ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CodeUnitReverseLookup; /** * @since Class available since Release 1.0.0 */ class Wizard { /** * @var array */ private $lookupTable = []; /** * @var array */ private $processedClasses = []; /** * @var array */ private $processedFunctions = []; /** * @param string $filename * @param int $lineNumber * * @return string */ public function lookup($filename, $lineNumber) { if (!isset($this->lookupTable[$filename][$lineNumber])) { $this->updateLookupTable(); } if (isset($this->lookupTable[$filename][$lineNumber])) { return $this->lookupTable[$filename][$lineNumber]; } else { return $filename . ':' . $lineNumber; } } private function updateLookupTable() { $this->processClassesAndTraits(); $this->processFunctions(); } private function processClassesAndTraits() { foreach (array_merge(get_declared_classes(), get_declared_traits()) as $classOrTrait) { if (isset($this->processedClasses[$classOrTrait])) { continue; } $reflector = new \ReflectionClass($classOrTrait); foreach ($reflector->getMethods() as $method) { $this->processFunctionOrMethod($method); } $this->processedClasses[$classOrTrait] = true; } } private function processFunctions() { foreach (get_defined_functions()['user'] as $function) { if (isset($this->processedFunctions[$function])) { continue; } $this->processFunctionOrMethod(new \ReflectionFunction($function)); $this->processedFunctions[$function] = true; } } /** * @param \ReflectionFunctionAbstract $functionOrMethod */ private function processFunctionOrMethod(\ReflectionFunctionAbstract $functionOrMethod) { if ($functionOrMethod->isInternal()) { return; } $name = $functionOrMethod->getName(); if ($functionOrMethod instanceof \ReflectionMethod) { $name = $functionOrMethod->getDeclaringClass()->getName() . '::' . $name; } if (!isset($this->lookupTable[$functionOrMethod->getFileName()])) { $this->lookupTable[$functionOrMethod->getFileName()] = []; } foreach (range($functionOrMethod->getStartLine(), $functionOrMethod->getEndLine()) as $line) { $this->lookupTable[$functionOrMethod->getFileName()][$line] = $name; } } } code-unit-reverse-lookup-1.0.0/tests/000077500000000000000000000000001265755037200175355ustar00rootroot00000000000000code-unit-reverse-lookup-1.0.0/tests/WizardTest.php000066400000000000000000000016561265755037200223560ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CodeUnitReverseLookup; /** * @covers SebastianBergmann\CodeUnitReverseLookup\Wizard */ class WizardTest extends \PHPUnit_Framework_TestCase { /** * @var Wizard */ private $wizard; protected function setUp() { $this->wizard = new Wizard; } public function testMethodCanBeLookedUp() { $this->assertEquals( __METHOD__, $this->wizard->lookup(__FILE__, __LINE__) ); } public function testReturnsFilenameAndLineNumberAsStringWhenNotInCodeUnit() { $this->assertEquals( 'file.php:1', $this->wizard->lookup('file.php', 1) ); } }