shaggy8871 / php-rx

PHP-specific implementation of Rx JSON/YAML validator
GNU General Public License v3.0
11 stars 2 forks source link

Suggestion: Lower responsibilities of Loader #3

Open Lewiscowles1986 opened 5 years ago

Lewiscowles1986 commented 5 years ago

The loader class takes on deserializing files from a file-name to Objects currently. In #1 I suggested making sure it always returned objects. While looking at it and thinking about it writing #2 it seemed the class method is destined to grow and grow, taking on more responsibilities.

Currently the class takes on loading files without a file-exists check, it loads all bytes in one hit which uses all RAM, doesn't catch exceptions or errors so breaks encapsulation and seems fairly rigid. If I wanted to block files of 1MB or more, it would be difficult. If I wanted to load a json file which contained 3 hyphens, problems, etc.

It also takes on validation, which although I applaud, is similarly rigid. The class body will grow and grow under the current structure.

More interfaces would help to address this.

shaggy8871 commented 5 years ago

Thanks @Lewiscowles1986 - I'll take a look at your PRs.

shaggy8871 commented 5 years ago

Agreed - a JsonLoader and YamlLoader class would make more sense in this case than a simple RxLoader. Perhaps RxLoader could become an abstract class instead of a final class to enable this.