elrido / ZeroBin

This Project has been renamed and moved to
https://github.com/PrivateBin/PrivateBin
Other
85 stars 8 forks source link

Refactoring #32

Closed elrido closed 8 years ago

elrido commented 9 years ago

TL;DR: after adding many features, a bit of cleanup is needed IMO

After having added quite some additional features in 0.20 and 0.21 mainly zerobin.php starts to ballon a little and I started to get quite a few bugs in the logic recently (thanks @Hexalyse for finding some of them).

Lots of the code in there is about validation before data manipulation. If we think of zerobin as a controller, our example is getting a bit to fat to maintain. Also these issues slipped my unit tests, as lots of this logic can only be tested by running the full app (case in point: tst/zerobin.php is 7 times as large as the next largest unit test). If the logic would be more modular, it would be easier to test and maintain and therefore safer and more bug free.

Suggested refactoring targets:

I am not yet quite so sure what to do about the JS part. Maybe it would be an option to start to look into angular? In any case I'd like to look into things like JSUnit und JSDocs both to avoid issues in there and help us get an overview of it.

Hexalyse commented 9 years ago

Nice initiative !

About AngularJS, I'm currently using this technology at work, and I'm wondering: wouldn't it be a bit "overkill" for this App ? Considering the original aim of ZeroBin was to be "minimalistic", using AngularJS wouldn't really be minimalistic, since it's a big framework.

elrido commented 9 years ago

Yeah, using Angular in the company, too. Its quite rich and usually you use it with build tools (i.e. gulp or similar). I can see it becoming an overkill for the intended use case of ZeroBin. Maybe it could be done as an alternative client at a later point.

I see that Vikstrous had started to use the Backbone.js library in his fork. This seems more lightweight, but I have no experience with it.

I am mainly looking for the right approach to keep zerobin.js easy to maintain. Maybe some JS guru has some suggestions? Will focus on the php part for now.

elrido commented 9 years ago

I made some progress on this during the weekend. Found and solved a few issues that I had not yet discovered. Implemented a "request" instead of a "router", routing is still done in the main class, but is now only a few lines. All in all, zerobin.php shrank by 200+ lines or over a third. Of course the additional classes more then make up for that, but it should now be a lot easier to maintain.

To my surprise I discovered that DELETE and PUT are not available on all webservers by default. Now I can work around that on my system, but many shared hosting users may not. So for now we will have to work with GET for DELETEs and POST instead of PUT to stay compatible among all installations.

The API part is already partially implemented, but I will have to extend the data classes a bit to allow more targeted access on the comments, to be able to support all of the above listed operations.

elrido commented 9 years ago

The main refactoring points and most API changes are complete. The only missing operations are "list child comments" and "read single comment". These are (currently) not required.

The JSON-LD-notation and -context was implemented is to make it possible ZeroBin installs on different versions can discover what features are supported by another install i.e. for scenarios as described in #33. For the same reason CORS headers were implemented. The comment_count and comment_offset were added in preparation of #44.

elrido commented 8 years ago

As the PHP and API part of the issue were resolved, but no input on the JS part was received, I am closing the issue for now.