pax_global_header00006660000000000000000000000064130564574210014521gustar00rootroot0000000000000052 comment=4419fcdb5eabb9caa61a27c7a1db532a6b55dd18 code-unit-reverse-lookup-1.0.1/000077500000000000000000000000001305645742100163675ustar00rootroot00000000000000code-unit-reverse-lookup-1.0.1/.gitignore000066400000000000000000000000371305645742100203570ustar00rootroot00000000000000/.idea /composer.lock /vendor code-unit-reverse-lookup-1.0.1/.php_cs000066400000000000000000000036211305645742100176460ustar00rootroot00000000000000files() ->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.1/.travis.yml000066400000000000000000000005601305645742100205010ustar00rootroot00000000000000language: php php: - 5.6 - 7.0 - 7.0snapshot - 7.1 - 7.1snapshot - master sudo: false before_install: - composer self-update - composer clear-cache install: - travis_retry composer update --no-interaction --no-ansi --no-progress --no-suggest --optimize-autoloader --prefer-stable script: - ./vendor/bin/phpunit notifications: email: false code-unit-reverse-lookup-1.0.1/ChangeLog.md000066400000000000000000000003511305645742100205370ustar00rootroot00000000000000# 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.1/LICENSE000066400000000000000000000030271305645742100173760ustar00rootroot00000000000000code-unit-reverse-lookup Copyright (c) 2016-2017, 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.1/README.md000066400000000000000000000007671305645742100176600ustar00rootroot00000000000000# code-unit-reverse-lookup Looks up which function or method a line of code belongs to. ## Installation You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/): composer require sebastian/code-unit-reverse-lookup If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency: composer require --dev sebastian/code-unit-reverse-lookup code-unit-reverse-lookup-1.0.1/build.xml000066400000000000000000000014421305645742100202110ustar00rootroot00000000000000 code-unit-reverse-lookup-1.0.1/composer.json000066400000000000000000000012421305645742100211100ustar00rootroot00000000000000{ "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 || ^7.0" }, "require-dev": { "phpunit/phpunit": "^5.7 || ^6.0" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.0.x-dev" } } } code-unit-reverse-lookup-1.0.1/phpunit.xml000066400000000000000000000014161305645742100206020ustar00rootroot00000000000000 tests src code-unit-reverse-lookup-1.0.1/src/000077500000000000000000000000001305645742100171565ustar00rootroot00000000000000code-unit-reverse-lookup-1.0.1/src/Wizard.php000066400000000000000000000055451305645742100211400ustar00rootroot00000000000000 * * 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.1/tests/000077500000000000000000000000001305645742100175315ustar00rootroot00000000000000code-unit-reverse-lookup-1.0.1/tests/WizardTest.php000066400000000000000000000016741305645742100223520ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\CodeUnitReverseLookup; use PHPUnit\Framework\TestCase; /** * @covers SebastianBergmann\CodeUnitReverseLookup\Wizard */ class WizardTest extends 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) ); } }