sikor4's avatar
Level 1

Balancing SOLID with Real-World Constraints

I'm looking for some insights on a fairly academic point, but it's been on my mind as I think through some design choices. In a service class, I’ve used ?? config to set a default path if none is provided, like in this example

public function __construct(
    protected FetcherInterface $imageFetcher,
    protected StorageInterface $storage,
    string $imageStoragePath = null
) {
    $this->imageStoragePath = $imageStoragePath ?? config('paths.image_storage_path');
}

I’m debating whether this might break SRP or dilute dependency injection principles a bit, though it seems more convention-based. With more extensive experience, do people find this kind of config-driven fallback practical in bigger projects, or does it turn into a source of tech debt? Curious if this is something others think about in large-scale apps, or if it’s just a matter of pragmatism versus purity in design.

0 likes
4 replies
Tray2's avatar

I don't think it does, I mean the method sets a default path, and if none is given uses a default one.

maxxd's avatar

I also don't think it does, however I do find it strange to use a config setting as a fallback. Typically it'd be along the lines of config('paths.image_storage_path', $imageStoragePath');,

psrz's avatar

@maxxd

So when you create an instance of that class even when you explicitly pass the parameter for the image storage path it gets discarded in favor of whatever the config setting has...

I don't think that's how it's supposed to work. I mean, the way I see it, the optional parameter for the image path is how you override the default config setting

maxxd's avatar

@psrz

The question is whether you should be overwriting the default. If you've got different storage locations for different users then yes, but that wasn't how I understand the question and - to my way of thinking - it isn't a good way to do it. It smells like security by obscurity; if certain users should be associated with certain uploads, keep track of that and use a permissions system to check it.

Please or to participate in this conversation.