Skip to content

Merge release 0.1.1 into 0.2.x #11

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

Merged
merged 4 commits into from
Dec 3, 2020
Merged
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
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,25 @@ All notable changes to this project will be documented in this file, in reverse

- Nothing.

## 0.1.1 - 2020-12-03


-----

### Release Notes for [0.1.1](https://github.com/open-code-modeling/php-filter/milestone/2)

0.1.x bugfix release (patch)

### 0.1.1

- Total issues resolved: **1**
- Total pull requests resolved: **0**
- Total contributors: **1**

#### bug

- [10: Method name filter and upper letters issue](https://github.com/open-code-modeling/php-filter/issues/10) thanks to @sandrokeil

## 0.1.0 - 2020-11-30


Expand Down
25 changes: 25 additions & 0 deletions src/Filter/UpperToLower.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

/**
* @see https://github.com/open-code-modeling/php-filter for the canonical source repository
* @copyright https://github.com/open-code-modeling/php-filter/blob/master/COPYRIGHT.md
* @license https://github.com/open-code-modeling/php-filter/blob/master/LICENSE.md MIT License
*/

declare(strict_types=1);

namespace OpenCodeModeling\Filter\Filter;

final class UpperToLower extends AbstractFilter
{
public function __invoke(string $value): string
{
$value = ($this->filter)($value);

if (1 === \preg_match('/^[A-Z]+$/', $value)) {
return \strtolower($value);
}

return $value;
}
}
3 changes: 2 additions & 1 deletion src/FilterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use OpenCodeModeling\Filter\Filter\LowerCaseFirst;
use OpenCodeModeling\Filter\Filter\NormalizeLabel;
use OpenCodeModeling\Filter\Filter\UpperCaseFirst;
use OpenCodeModeling\Filter\Filter\UpperToLower;

final class FilterFactory
{
Expand Down Expand Up @@ -93,7 +94,7 @@ public static function propertyNameFilter(): callable
*/
public static function methodNameFilter(): callable
{
return new LowerCaseFirst(self::normalizeFilter());
return new LowerCaseFirst(self::normalizeFilter(new UpperToLower()));
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/FilterFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ public function it_filters_method_name(string $label): void
$this->assertSame('addBuilding', ($filter)($label));
}

/**
* @test
*/
public function it_filters_method_name_with_only_upper_letters(): void
{
$filter = FilterFactory::methodNameFilter();
$this->assertSame('ny', ($filter)('NY'));
}

/**
* @test
* @dataProvider providerForLabel
Expand Down