M
M
montray2018-03-29 22:11:30
PHP
montray, 2018-03-29 22:11:30

How to refactor this?

In general, I am writing a data importer for an online store from a web api of a third-party service (something similar to 1C). And I ran into a problem that the import class already exceeds 2500 lines, which consists of the same type methods of the importProduct type, which takes data from the api and processes it if necessary; and addProduct type methods that take data from the previous method and write it to the database via AR(yii2). As a result, it turns out that all these methods do the same thing, but it still doesn’t work to reduce everything to one implementation due to some difference in the models. It turns out that all my code is in a functional style, but I would like it to be in an object style, but for a week now I have been racking my brains on how to do it so that it is both beautiful and readable and at least follows the principles of SOLID. And at the moment, the principles of STUPID are on the face :)
I would like to ask experienced people for advice on how to do it better, and whether it makes sense at all, because. in principle, it all works, but if something changes somewhere, then almost every method will have to be redone.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2018-03-30
@quiex

Of course, it is difficult to judge blindly, but based on common practices, the recording can be taken out to a separate level - the repository layer. Try to arrange the same type of processing functions with the “strategy” pattern, with the corresponding injections of implementation contracts.

K
Kirill Gorelov, 2018-03-29
@Kirill-Gorelov

I think here it is necessary to be guided by such principle: "Works, do not touch".
Sometimes I think it's better to rewrite everything from scratch than to try to fix it.
In addition, here, as I understand it, the problem is not in the speed of work, just in the fact that you don’t like how it looks? Then it's definitely worth rewriting everything from scratch if it's important. And then you decide for yourself.
This is purely my opinion.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question