-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Allow generated classes target dir to be null #37
Conversation
Because of the string casting, in my code I have to call `setGeneratedClassesTargetDir()` like this: ```php class HydrateUsingGeneratedHydrator implements Hydrate { /** * @var string|null */ private $cacheDir; public function __construct($cacheDir) { $this->cacheDir = $cacheDir; } public function hydrate(array $data, $object) { $configuration = new Configuration(get_class($object)); if ($this->cacheDir !== null) { $configuration->setGeneratedClassesTargetDir($this->cacheDir); } ... } ``` The proposed change allows me to just call `$configuration->setGeneratedClassesTargetDir($this->cacheDir);` without the extra `if` clause.
@@ -164,7 +164,7 @@ public function getGeneratedClassesNamespace() | |||
*/ | |||
public function setGeneratedClassesTargetDir($generatedClassesTargetDir) | |||
{ | |||
$this->generatedClassesTargetDir = (string) $generatedClassesTargetDir; | |||
$this->generatedClassesTargetDir = $generatedClassesTargetDir; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This breaks internal data integrity of the Configuration
object, and may cause exceptions at a later execution point in time.
@matthiasnoback I don't understand the use-case. What are you passing in as a path? |
I agree that it isn't ideal from the point of view of internal data integrity. But if (!(is_string($generatedClassesTargetDir) || $generatedClassesTargetDir === null)) {
// throw exception
}
$this->generatedClassesTargetDir = $generatedClassesTargetDir; |
Maybe I wasn't clear: the problem is that my |
@matthiasnoback should I apply stricter validation and throw an exception? I'm fine with that approach. |
That, or maybe $this->generatedClassesTargetDir = $generatedClassesTargetDir === null ? null : (string) $generatedClassesTargetDir; |
@matthiasnoback I'd rather always expect a |
Okay, no problem. Then I guess we'll leave it as is. |
@matthiasnoback the docblock says |
Well, in theory the current code would also accept |
Because of the string casting, in my code I have to call
setGeneratedClassesTargetDir()
like this:The proposed change allows me to just call
$configuration->setGeneratedClassesTargetDir($this->cacheDir);
without the extraif
clause.