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

Assignment from yield reports a processing error #804

Closed
6 tasks done
Nessworthy opened this issue Jul 20, 2020 · 6 comments · Fixed by pdepend/pdepend#694
Closed
6 tasks done

Assignment from yield reports a processing error #804

Nessworthy opened this issue Jul 20, 2020 · 6 comments · Fixed by pdepend/pdepend#694
Assignees

Comments

@Nessworthy
Copy link

Nessworthy commented Jul 20, 2020

  • PHPMD version: 2.8.1 / 2.8.1snapshot202002241446
  • PHP Version: 7.4.8 (both)
  • Installation type: composer / phar
  • Operating System / Distribution & Version: Windows 10

Also tested on 2.8.1 from source at cf8677bbd8c291f7f6ed6437f5c941a49ebc2473

Current Behavior

Running phpmd reports the following processing error:

Unexpected token: }, line: 6, col: 1, file: /path/to/script.php.

Expected Behavior

No processing errors.

Steps To Reproduce:

Using the following script:

<?php declare(strict_types=1);

function test_function(): Generator
{
    $result = yield true;
}

And running phpmd script.php text cleancode

or

php phpmd.phar script.php text cleancode

Checks before submitting

  • Be sure that there isn't already an issue about this. See: Issues list
    • Another prior issue around yield, from a previous version reporting and a different error, but it is closed off.
  • Be sure that there isn't already a pull request about this. See: Pull requests
  • I have added every step to reproduce the bug.
  • If possible I added relevant code examples.
  • This issue is about 1 bug and nothing more.
  • The issue has a descriptive title. For example: "JSON rendering failed on Windows for filenames with space".
@kylekatarnls
Copy link
Member

Sure PHPMD should handle it, but as for my personal opinion, having an output (yield) and an assignation ($result =) in the same line of code is a code smell.

A clean code would be:

<?php declare(strict_types=1);

function test_function(): Generator
{
    $result = true;

    yield $result;
}

@Nessworthy
Copy link
Author

Nessworthy commented Jul 20, 2020

It's possible to need to make use of both input and output while working with generators, e.g.:

<?php declare(strict_types=1);

function number_addition_generator(int $number): Generator {
    $toAdd = 0;
    while (true) {
        $number += $toAdd;
        $toAdd = yield $number;
    }
}

$generator = number_addition_generator(0);

$generator->current(); // Returns 0
$generator->send(1);   // Returns 1
$generator->send(10);  // Returns 11
$generator->send(100); // Returns 111

Forgive the stupid example 😅

@kylekatarnls
Copy link
Member

Indeed, I get the point.

@bug-tape
Copy link

bug-tape commented May 3, 2021

Similar problem when using this short cut to stop a generator:

<?php
function some_generator() {
    return yield "last";
}

@wietsewarendorff
Copy link

Any progress on this?

@kylekatarnls
Copy link
Member

kylekatarnls commented Nov 28, 2023

Cause found, you can test the fix with:

composer require "pdepend/pdepend:dev-master as 2.16.0"

@kylekatarnls kylekatarnls self-assigned this Nov 28, 2023
kylekatarnls added a commit to pdepend/pdepend that referenced this issue Nov 28, 2023
renovate bot added a commit to line/line-bot-sdk-php that referenced this issue Dec 11, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [phpmd/phpmd](https://phpmd.org/)
([source](https://togithub.com/phpmd/phpmd)) | `2.14.1` -> `2.15.0` |
[![age](https://developer.mend.io/api/mc/badges/age/packagist/phpmd%2fphpmd/2.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/packagist/phpmd%2fphpmd/2.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/packagist/phpmd%2fphpmd/2.14.1/2.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/packagist/phpmd%2fphpmd/2.14.1/2.15.0?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>phpmd/phpmd (phpmd/phpmd)</summary>

###
[`v2.15.0`](https://togithub.com/phpmd/phpmd/blob/HEAD/CHANGELOG#phpmd-2150-20231211)

[Compare
Source](https://togithub.com/phpmd/phpmd/compare/2.14.1...2.15.0)

\========================

- Added [#&#8203;1036](https://togithub.com/phpmd/phpmd/issues/1036)
\[CLI] Allow option and value separated with equal sign
-   Require pdepend/pdepend 2.16.1
- Support PHP 8.3
[pdepend/pdepend#699](https://togithub.com/pdepend/pdepend/issues/699)
- Support Symfony 7
[pdepend/pdepend#692](https://togithub.com/pdepend/pdepend/issues/692)
- Fixed
[pdepend/pdepend#691](https://togithub.com/pdepend/pdepend/issues/691)
Float parsing for number starting with 0.
- Fixed
[pdepend/pdepend#689](https://togithub.com/pdepend/pdepend/issues/689)
Handle conversion to/detection of UTF-8 encoding using either mbstring
PHP extension or the polyfill provided by Symfony
- Fixed
[pdepend/pdepend#687](https://togithub.com/pdepend/pdepend/issues/687)
Parsing the correct comment for method doc-block (Allow correct
SuppressWarnings annotation handling on PHPMD)
([phpmd/phpmd#914)
- Fixed
[pdepend/pdepend#694](https://togithub.com/pdepend/pdepend/issues/694)
Handle yield termination depending on context
([phpmd/phpmd#804)
- Fixed [#&#8203;1044](https://togithub.com/phpmd/phpmd/issues/1044)
strict option on applyOnClassMethods
- Documented
[#&#8203;1041](https://togithub.com/phpmd/phpmd/issues/1041) Mention
public key used for signing the Phars
- Documented
[#&#8203;1042](https://togithub.com/phpmd/phpmd/issues/1042) Document
installation with PHIVE

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/line/line-bot-sdk-php).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy44Ny4yIiwidXBkYXRlZEluVmVyIjoiMzcuODcuMiIsInRhcmdldEJyYW5jaCI6Im1hc3RlciJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
@ravage84 ravage84 added this to the 2.x (unspecific) milestone May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

5 participants