The background of this question is Fourier series. I was suppose to find the Fourier series of $f(x)=x$, in the interval $-2<x<2$ with $f(x+4)=f(x)$.
It is mandatory to have a periodic function to find it's Fourier series.
How come $f(x)=x$ is periodic?
A function $f$ is said to be periodic if there exists a positive number $P$, such that $f (x + P ) = f (x)$
The source of confusion here seems to be that you are conflating two different functions. One is the function $f$ in the title of your question and in the next-to-last sentence of your question; it is defined by $f(x)=x$ for all $x$, and it is not periodic. The other is the function, which you also called $f$ but which I'll call $g$ to avoid confusion, whose graph you included in the question. It is periodic, with period 4, because $g(x+4)=g(x)$ for all $x$. The two functions are related by the fact that $f(x)=g(x)$ when $x$ is between $-2$ and $2$; for other values of $x$, $f(x)$ and $g(x)$ are quite different.
As $g$ is periodic, it makes sense to talk about its Fourier series. In fact, that series will converge to $g$ at all points except where $g$ is discontinuous (or undefined, it's hard to tell from the graph). Since $f$ and $g$ agree on the interval from $-2$ to $2$, the Fourier series of $g$ will converge to $f$ on that interval (but not outside that interval).