Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Add auto_composer command. #32

Merged
merged 3 commits into from
May 7, 2018

Conversation

bmiklautz
Copy link

When auto_composer is used development mode is set based on the
environment Variable COMPOSER_DEV_MODE. If it's undefined the mode
isn't touched. If its anything else then 0 developer mode is enabled.

This can be used as post-[install|update]-cmd for composer to enable
development mode based on the mode composer was called with (--dev vs. --no-dev):
...
"scripts": {
"development-auto": "zf-development-mode auto_composer",
"post-install-cmd": ["@development-auto" ],
"post-update-cmd": [ "@development-auto" ],
}
...

Copy link
Member

@weierophinney weierophinney left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, this looks like a nice addition. I'll take care of the changes for which I left feedback during merge.

Thanks, @bmiklautz !

src/Auto.php Outdated
/**
* @var value of COMPOSER_DEV_MODE
*/
private $composer_dev_mode;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use camelCase for property names.

src/Auto.php Outdated
}
}
// not running under composer
echo 'COMPOSER_DEV_MODE not set. Nothing to do.' . PHP_EOL;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please invert the statements, so that we can return early. As an example:

if ($this->composerDevMode === '') {
    echo 'COMPOSER_DEV_MODE not set; nothing to do.' . PHP_EOL;
    return 0;
}

if ($this->composerDevMode === '0') {
    $disable = $this->projectDir, $this->errorStream);
    return $disable();
}

$enable = new Enable($this->projectDir, $this->errorStream);
return $enable;

Changes like this make it easier to determine the various behaviors, boiling this one down to exactly three.

src/Command.php Outdated
@@ -42,6 +42,9 @@ public function __invoke(array $arguments)
case 'status':
$status = new Status();
return $status();
case 'auto_composer':
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We typically use dash-separated names, so this should become auto-composer.

src/Auto.php Outdated

namespace ZF\DevelopmentMode;

class Auto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename this class to mimic the command itself: AutoComposer.

bmiklautz and others added 3 commits May 7, 2018 10:23
When auto_composer is used development mode is set based on the
environment Variable COMPOSER_DEV_MODE. If it's undefined the mode
isn't touched. If its anything else then 0 developer mode is enabled.

This can be used as post-[install|update]-cmd for composer to enable
development mode based on the mode composer was called with (--dev vs. --no-dev):
...
"scripts": {
    "development-auto": "zf-development-mode auto_composer",
    "post-install-cmd": ["@development-auto" ],
    "post-update-cmd": [ "@development-auto" ],
}
...
* move functionality to an extra class
* add the corresponding tests
- Renames class to `AutoComposer`
- Renames command to `auto-composer`
- Rewrites `AutoComposer::__invoke()` to do a conditional per behavior,
  with each returning. In doing so, identified an issue with how it
  detected absence of a `COMPOSER_DEV_MODE` value, as well as inability
  to correctly report an invalid value was provided.
@weierophinney weierophinney changed the base branch from master to develop May 7, 2018 15:24
@weierophinney weierophinney merged commit 4032492 into zfcampus:develop May 7, 2018
weierophinney added a commit that referenced this pull request May 7, 2018
@bmiklautz bmiklautz deleted the auto_composer branch February 7, 2019 11:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants