Skip to content

Commit b3ab644

Browse files
committed
Improve sources and fix tests
1 parent ed818a1 commit b3ab644

12 files changed

+20
-174
lines changed

README.md

+4-19
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ $result = pipe($arg)
9999
->array_merge($result, _);
100100
```
101101

102-
103102
## Working With Value
104103

105104
To pass a value as an argument to a function, use the
@@ -130,7 +129,7 @@ To get the value, use one of the options:
130129
$context = pipe('hello')->strtoupper;
131130

132131
var_dump($context);
133-
// object(Serafim\Pipe\Pipe)#8 (1) { ... }
132+
// object(Fun\Pipe\Pipe)#8 (1) { ... }
134133

135134
var_dump($context());
136135
// string(5) "HELLO"
@@ -150,23 +149,6 @@ namespace Example {
150149
}
151150
```
152151

153-
During a `pipe` call, it implicitly uses the namespace in which it is called
154-
as a priority:
155-
156-
```php
157-
namespace {
158-
echo (pipe()->foo)(); // 'foo'
159-
}
160-
161-
namespace Example {
162-
echo (pipe()->foo)(); // 'Example\\foo'
163-
}
164-
165-
namespace Another {
166-
echo (pipe()->foo)(); // 'foo'
167-
}
168-
```
169-
170152
Let's try to manage the namespace:
171153

172154
```php
@@ -202,3 +184,6 @@ pipe()
202184
->a // Call "a()"
203185
;
204186
```
187+
188+
> Note that the behavior of the `->use()` method differs depending on whether
189+
> the second argument is passed.

bin/pipe

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#!/usr/bin/env php
22
<?php
3+
34
/**
45
* This file is part of Pipe package.
56
*
67
* For the full copyright and license information, please view the LICENSE
78
* file that was distributed with this source code.
89
*/
9-
declare(strict_types=1);
1010

11+
declare(strict_types=1);
1112

1213
use Composer\Autoload\ClassLoader;
1314
use Symfony\Component\Console\Application;

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
],
2424
"require": {
2525
"php": ">=7.4",
26+
"symfony/polyfill-php80": "^1.0",
2627
"phpfn/placeholder": "^2.0"
2728
},
2829
"autoload": {

src/Console/BuildAutocompleteCommand.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
use Symfony\Component\Console\Output\OutputInterface;
2424

2525
/**
26-
* Class BuildAutocompleteCommand
27-
*
2826
* @mixin Pipe
2927
*/
3028
class BuildAutocompleteCommand extends Command
@@ -83,7 +81,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
8381
'classes' => [
8482
ClassGenerator::fromArray([
8583
'name' => 'Pipe',
86-
'namespacename' => 'Serafim\\Pipe',
84+
'namespacename' => 'Fun\\Pipe',
8785
'docblock' => $docblock,
8886
]),
8987
],
@@ -142,7 +140,8 @@ private function getDocBlock(): array
142140

143141
$tags[] = [
144142
'name' => 'method',
145-
'description' => 'PipeInterface|$this ' . ($methods[] = $name) . '(' . \implode(', ', $parameters) . ')',
143+
'description' => 'PipeInterface|$this ' .
144+
($methods[] = $name) . '(' . \implode(', ', $parameters) . ')',
146145
];
147146
}
148147

src/Exception/FunctionNotFoundException.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Fun\Pipe\Exception;
1313

14-
/**
15-
* Class FunctionNotFoundException
16-
*/
1714
class FunctionNotFoundException extends \Error
1815
{
1916
}

src/Pipe.php

+4-7
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ final class Pipe implements PipeInterface
7979
*
8080
* @var string|null
8181
*/
82-
private $use;
82+
private ?string $use = null;
8383

8484
/**
8585
* The namespace that using for all function prefixes.
8686
*
8787
* @var string
8888
*/
89-
private $namespace;
89+
private string $namespace;
9090

9191
/**
9292
* Pipe constructor.
@@ -96,8 +96,7 @@ final class Pipe implements PipeInterface
9696
*/
9797
public function __construct($value = null, string $namespace = null)
9898
{
99-
$this->namespace = $namespace ?? Trace::getNamespace(__DIR__);
100-
99+
$this->namespace = $namespace ?? '';
101100
$this->value = $this->resolveValue($value);
102101
}
103102

@@ -154,9 +153,7 @@ public function __invoke(...$args)
154153
*/
155154
private function applyArguments(array $arguments): array
156155
{
157-
return Placeholder::map($arguments, function () {
158-
return $this->value;
159-
});
156+
return Placeholder::map($arguments, fn() => $this->value);
160157
}
161158

162159
/**

src/PipeInterface.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Fun\Pipe;
1313

14-
/**
15-
* Interface PipeInterface
16-
*/
1714
interface PipeInterface
1815
{
1916
/**

src/RendererTrait.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Fun\Pipe;
1313

14-
/**
15-
* Trait RendererTrait
16-
*/
1714
trait RendererTrait
1815
{
1916
/**
@@ -82,6 +79,7 @@ private function splitIterableValues(iterable $values): string
8279
private function renderAsJson($value): string
8380
{
8481
$result = \json_encode($value);
82+
8583
if (\json_last_error() !== \JSON_ERROR_NONE) {
8684
return $this->renderFallback($value);
8785
}

src/Trace.php

-118
This file was deleted.

tests/FunctionPipingTestCase.php

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111

1212
namespace Fun\Pipe\Tests;
1313

14-
/**
15-
* Class TestFunctionPiping
16-
*/
1714
class FunctionPipingTestCase extends TestCase
1815
{
1916
/**

tests/NamespacedFunctionsTestCase.php

+2-8
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
use Fun\Pipe\PipeInterface;
1515

16-
/**
17-
* Class NamespacedFunctionsTestCase
18-
*/
1916
class NamespacedFunctionsTestCase extends TestCase
2017
{
2118
/**
@@ -57,7 +54,7 @@ public function testGlobalFunctionFromNamespace(): void
5754
public function testExportedFunctionFromNamespace(): void
5855
{
5956
$this->assertSame(
60-
__NAMESPACE__ . '\\test_foo',
57+
'test_foo',
6158
(pipe(true)->test_foo)()
6259
);
6360
}
@@ -85,10 +82,7 @@ public function testFunctionWithChangedContext(): void
8582

8683
$this->assertSame('Some\\Any\\test_foo', $context());
8784

88-
$context = $context
89-
->test_foo;
90-
91-
$this->assertSame(__NAMESPACE__ . '\\test_foo', $context());
85+
$this->assertSame('test_foo', ($context->test_foo)());
9286
}
9387

9488
/**

tests/stubs/functions.php

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@
1111

1212
namespace Fun\Pipe\Tests {
1313

14-
function test_foo()
14+
function test_foo(): string
1515
{
1616
return __FUNCTION__;
1717
}
1818
}
19-
2019
namespace {
2120

22-
function global_foo()
21+
function global_foo(): string
2322
{
2423
return __FUNCTION__;
2524
}
2625

27-
function test_foo()
26+
function test_foo(): string
2827
{
2928
return __FUNCTION__;
3029
}
3130
}
32-
3331
namespace Some\Any {
3432

3533
function test_foo()

0 commit comments

Comments
 (0)