6. Given that $y=f(x)$ is a function with a period of 2, when $x \in[-1,1]$, $f(x)=x^{2}+1$, when $x \in[-3,3]$, the analytical expression of $f(x)$ is $\qquad$

Translate the above text into English, please retain the original text's line breaks and format, and output the translation result directly.
6. $f(x)=\left\{\begin{array}{l}x^{2}+4 x+5, x \in[-3,-1] \\ x^{2}+1, x \in[-1,1] \\ x^{2}-4 x+5, x \in[1,3]\end{array}\right.$

When $x \in[-3,-1]$, then $x+2 \in[-1,1], f(x+2)=(x+2)^{2}+1=f(x)$; When $x \in[1$, $3]$, then $x-2 \in[-1,1], f(x-2)=(x-2)^{2}+1=f(x)$.